{% import "_includes/forms" as forms %} {% if sections|length %} {% set sectionRows = [] %} {% for sectionInfo in sections %} {% set section = sectionInfo.section %} {% set sectionSettings = settings.getSection(section.uid) %} {% set idPrefix = 'sections-'~section.handle %} {% set namePrefix = 'sections['~section.handle~']' %} {# If the section is enabled, add a blank author option to the top in case the selected author no longer exists #} {% set authorOptions = sectionInfo.authorOptions %} {% if sectionSettings.allowGuestSubmissions %} {% set authorOptions = [{label: '', value: ''}]|merge(authorOptions) %} {% endif %} {% set sectionRows = sectionRows|merge({ (section.handle): { sectionName: section.name|t('site'), allowGuestSubmissions: include('_includes/forms/lightswitch', { id: idPrefix~'-allowGuestSubmissions', name: namePrefix~'[allowGuestSubmissions]', on: sectionSettings.allowGuestSubmissions, small: true }), authorUid: { options: authorOptions, value: sectionSettings.authorUid, hasErrors: sectionSettings.hasErrors('authorUid'), }, enabledByDefault: sectionSettings.enabledByDefault, runValidation: sectionSettings.runValidation, sectionUid: { value: '' ~ '', class: 'code centeralign' } } }) %} {% endfor %} {{ forms.editableTableField({ first: true, label: "Section Settings"|t('guest-entries'), instructions: "Choose which sections should allow guest submissions, and configure the section-specific settings."|t('guest-entries'), id: 'sections', name: 'sections', cols: { sectionName: { type: 'heading', heading: "Section"|t('guest-entries'), class: 'thin' }, allowGuestSubmissions: { type: 'heading', class: 'thin' }, authorUid: { type: 'select', heading: "Default Author"|t('guest-entries'), info: "Who the guest entries should be attributed to by default."|t('guest-entries'), class: 'leftalign' }, enabledByDefault: { type: 'lightswitch', heading: "Default Status"|t('guest-entries'), info: "Whether the guest entries should be enabled by default."|t('guest-entries'), class: 'leftalign' }, runValidation: { type: 'lightswitch', heading: "Validate?"|t('guest-entries'), info: "Whether the guest entries should be validated when submitted."|t('guest-entries'), class: 'leftalign' }, sectionUid: { type: 'html', heading: "UID"|t('guest-entries'), class: 'thin' } }, rows: sectionRows, staticRows: true }) }} {% else %}

{{ "No sections available."|t('guest-entries') }}

{% endif %} {% set systemCsrf = craft.app.config.general.enableCsrfProtection %} {{ forms.lightswitchField({ id: 'enableCsrfProtection', label: "Enable CSRF Protection?"|t('guest-entries'), instructions: "Whether `guest-entries/save` requests should be protected against CSRF attacks."|t('guest-entries'), name: 'enableCsrfProtection', on: systemCsrf and settings.enableCsrfProtection, disabled: not systemCsrf, warning: not systemCsrf ? "CSRF protection has been disabled at the system level."|t('guest-entries') }) }} {{ forms.textField({ id: 'entryVariable', label: "Entry Variable Name"|t('guest-entries'), instructions: "The template variable name that entry submissions should be assigned to, if there is a validation error."|t('guest-entries'), name: 'entryVariable', value: settings.entryVariable, class: 'code' }) }} {% js %} var $sectionRows = $('#{{ "sections"|namespaceInputId }}').children('tbody').children(), $lightswitches = $sectionRows.children('th:nth-child(2)').children('.lightswitch'); function updateSections() { $lightswitches.each(function() { if ($(this).data('lightswitch').on) { $(this).parent().nextAll('td').removeClass('disabled').find('select,div.lightswitch,input,button').attr('tabindex', '0'); } else { $(this).parent().nextAll('td').addClass('disabled').find('select,div.lightswitch,input,button').attr('tabindex', '-1'); } }); } $lightswitches.on('change', updateSections); Garnish.$doc.ready(function() { updateSections(); }); $('.uid-btn').on('click', function(ev) { ev.preventDefault(); var message = Craft.t('app', '{ctrl}C to copy.', { ctrl: (navigator.appVersion.indexOf('Mac') !== -1 ? '⌘' : 'Ctrl-') }); prompt(message, $(this).data('uid')); }); {% endjs %}