{{ errorList(errors) }}
{% endmacro %}
{% macro urlFormatInput(sectionType, brandNewSection, section) %}
{% if craft.isLocalized() or sectionType == 'structure' %}
{% if sectionType == 'structure' %}
{% if craft.isLocalized() %}
{% endif %}
{{ "Top-Level Entries"|t }}
{{ "Nested Entries"|t }}
{% endif %}
{% for locale in craft.i18n.getSiteLocales() %}
{% if craft.isLocalized() %}
{{ locale.id }}
{% endif %}
{% set value = ((section.type == sectionType or sectionType != 'single') and section.locales[locale.id] is defined ? section.locales[locale.id].urlFormat : null) %}
{{ _self.urlFormatText(sectionType, locale, section, 'urlFormat', value) }}
{% if sectionType == 'structure' %}
{% set value = ((section.type == 'structure') and section.locales[locale.id] is defined ? section.locales[locale.id].nestedUrlFormat : '{parent.uri}/{slug}') %}
{{ _self.urlFormatText(sectionType, locale, section, 'nestedUrlFormat', value) }}
{% endif %}
{% endfor %}
{% else %}
{% set locale = craft.i18n.getPrimarySiteLocale() %}
{% set value = ((section.type == sectionType or sectionType != 'single') and section.locales[locale.id] is defined ? section.locales[locale.id].urlFormat : null) %}
{{ _self.urlFormatText(sectionType, locale, section, 'urlFormat', value) }}
{% endif %}
{% endmacro %}
{% macro hasUrlsField(sectionType, section) %}
{% from "_includes/forms" import checkboxField %}
{{ checkboxField({
label: "Entries in this section have their own URLs"|t,
id: sectionType~'-hasUrls',
name: 'types['~sectionType~'][hasUrls]',
checked: section.hasUrls,
toggle: sectionType~'-url-settings'
}) }}
{% endmacro %}
{% macro templateField(sectionType, section) %}
{% from "_includes/forms" import textField %}
{{ textField({
label: "Entry Template"|t,
instructions: (sectionType == 'single' ? "The template to use when the entry’s URL is requested."|t : "The template to use when an entry’s URL is requested."|t),
id: sectionType~'-template',
class: 'ltr',
name: 'types['~sectionType~'][template]',
value: section.template,
errors: section.getErrors('template')
}) }}
{% endmacro %}
{% from _self import urlFormatInput, hasUrlsField, templateField %}
{% block content %}
{% if section.id %}{% endif %}
{{ forms.textField({
first: true,
label: "Name"|t,
instructions: "What this section will be called in the CP."|t,
id: 'name',
name: 'name',
value: section.name,
errors: section.getErrors('name'),
autofocus: true,
required: true,
translatable: true
}) }}
{{ forms.textField({
label: "Handle"|t,
instructions: "How you’ll refer to this section in the templates."|t,
id: 'handle',
class: 'code',
name: 'handle',
value: section.handle,
errors: section.getErrors('handle'),
required: true
}) }}
{% if craft.isLocalized() %}
{% set localesInput %}
{{ "Locale"|t }}
{{ "Default Entry Status"|t }}
{% for locale in craft.i18n.getSiteLocales() %}
{% set localeSelected = (brandNewSection or section.locales[locale.id] is defined) %}
{{ forms.lightswitch({
name: 'defaultLocaleStatuses['~locale.id~']',
on: (brandNewSection or not section.locales[locale.id] is defined or section.locales[locale.id].enabledByDefault),
small: true
}) }}
{% endfor %}
{% endset %}
{{ forms.field({
label: "Which locales should entries in this section target?"|t,
errors: section.getErrors('localeErrors'),
}, localesInput) }}
{% endif %}
{{ forms.selectField({
label: "Section Type"|t,
instructions: "What type of section is this?"|t ~ (section.id ? ' '~"Careful—changing this may result in data loss."|t~'' : ''),
id: 'type',
name: 'type',
options: typeOptions,
value: section.type,
toggle: true,
targetPrefix: '.type-',
errors: section.getErrors('type')
}) }}
{% if canBeHomepage %}
{{ forms.checkboxField({
label: "This is for the homepage"|t,
id: 'single-homepage',
name: 'types[single][homepage]',
checked: section.isHomepage(),
reverseToggle: 'single-uri-container'
}) }}
{% endif %}
{{ forms.field({
label: "URI"|t,
instructions: "What the entry URI should be."|t,
required: true,
errors: section.getErrors('urlFormat')
}, urlFormatInput('single', brandNewSection, section)) }}
{{ templateField('single', section) }}
{% set urlFormatParams = {
label: "Entry URL Format"|t,
instructions: "What the entry URLs should look like. You can include tags that output entry properties, such as {ex1} or {ex2}."|t({ ex1: '{slug}', ex2: '{postDate|date("Y")}' }),
required: true,
errors: section.getErrors('urlFormat')
} %}
{{ forms.textField({
label: "Max Levels"|t,
instructions: "The maximum number of levels this section can have. Leave blank if you don’t care."|t,
id: 'structure-maxLevels',
name: 'types[structure][maxLevels]',
value: section.maxLevels,
size: 5,
errors: section.getErrors('maxLevels')
}) }}
{% if not craft.isLocalized() %}
{% set locale = craft.i18n.getPrimarySiteLocale() %}
{% set value = (section.type != 'single' and section.locales[locale.id] is defined ? section.locales[locale.id].enabledByDefault : true) %}
{{ forms.lightswitchField({
label: "Default Entry Status"|t,
id: 'defaultEntryStatus',
name: 'defaultLocaleStatuses['~locale.id~']',
on: value
}) }}
{% endif %}
{{ forms.checkboxField({
label: "Enable versioning for entries in this section?"|t,
id: 'enableVersioning',
name: 'enableVersioning',
checked: section.enableVersioning
}) }}
{% endblock %}
{% includejs %}
{% if not section.handle %}new Craft.HandleGenerator('#name', '#handle');{% endif %}
{% for locale in craft.i18n.getSiteLocales() %}
{% if section.locales[locale.id] is not defined or not section.locales[locale.id].urlFormat %}
new Craft.EntryUrlFormatGenerator('#name', '#single-urlFormat-{{ locale.id }}');
new Craft.EntryUrlFormatGenerator('#name', '#channel-urlFormat-{{ locale.id }}', { suffix: '/{slug}' });
new Craft.EntryUrlFormatGenerator('#name', '#structure-urlFormat-{{ locale.id }}', { suffix: '/{slug}' });
{% endif %}
{% endfor %}
{% if brandNewSection %}
new Craft.EntryUrlFormatGenerator('#name', '#single-template');
new Craft.EntryUrlFormatGenerator('#name', '#channel-template', { suffix: '/_entry' });
new Craft.EntryUrlFormatGenerator('#name', '#structure-template', { suffix: '/_entry' });
{% endif %}
{% endincludejs %}