{% extends 'navigation/_layouts' %} {% import '_includes/forms' as forms %} {% import 'verbb-base/_macros' as macros %} {% set crumbs = [ { label: craft.navigation.getPluginName(), url: url('navigation') }, { label: 'Navigations' | t('navigation'), url: url('navigation/navs') }, ] %} {% set settingsClass = '' %} {% set fieldsClass = '' %} {% set permissionsClass = '' %} {% if nav is defined %} {% if nav.getErrors('name') or nav.getErrors('handle') or nav.getErrors('instructions') or nav.getErrors('maxLevels') or nav.getErrors('maxNodes') or nav.getErrors('propagationMethod') or nav.getErrors('siteSettings') %} {% set settingsClass = 'error' %} {% endif %} {% endif %} {% set tabs = [ { label: 'Settings' | t('app'), url: '#settings', class: settingsClass }, { label: 'Node Fields' | t('navigation'), url: '#node-fields', class: fieldsClass }, { label: 'Permissions' | t('navigation'), url: '#permissions', class: permissionsClass }, ] %} {% set fullPageForm = true %} {% set isNewNav = (nav is not defined or not nav.id) %} {% set formActions = [ { label: 'Save and continue editing' | t('app'), redirect: 'navigation/navs/edit/{id}' | hash, shortcut: true, retainScroll: true, }, not isNewNav ? { label: 'Duplicate' | t('navigation'), action: 'navigation/navs/duplicate-nav', params: { id: nav.id }, redirect: 'navigation/navs' | hash, }, not isNewNav ? { label: 'Delete' | t('app'), action: 'navigation/navs/delete-nav', redirect: 'navigation/navs' | hash, destructive: true, confirm: 'Are you sure you want to delete “{name}”?' | t('app', { name: nav.name, }), }, ] | filter %} {% if isNewNav %} {% set title = 'Create a new navigation' | t('navigation') %} {% else %} {% set title = nav.name %} {% endif %} {% set additionalButtons %} {% if not isNewNav %} {{ 'Edit Nodes' | t('navigation') }} {% endif %} {% endset %} {% block blockContent %} {% if not isNewNav %}{% endif %} {{ redirectInput('navigation/navs') }}
{{ forms.textField({ first: true, label: 'Name' | t('app'), instructions: 'Name of this navigation in the control panel.' | t('navigation'), id: 'name', name: 'name', value: (nav is defined ? nav.name : null), errors: (nav is defined ? nav.getErrors('name') : null), autofocus: true, required: true, }) }} {{ forms.textField({ label: 'Handle' | t('app'), instructions: 'How you’ll refer to this navigation in the templates.' | t('navigation'), id: 'handle', name: 'handle', class: 'code', value: (nav is defined ? nav.handle : null), errors: (nav is defined ? nav.getErrors('handle') : null), required: true, }) }} {{ forms.textareaField({ label: 'Instructions' | t('app'), instructions: 'Helper text to guide the author. Shown at the top of the page when editing a navigation.' | t('app'), id: 'instructions', class: 'nicetext', name: 'instructions', value: (nav is defined ? nav.instructions : null), errors: (nav is defined ? nav.getErrors('instructions') : null), }) }} {% if craft.app.getIsMultiSite() %} {% set siteRows = [] %} {% set siteErrors = nav.getErrors('siteSettings') %} {% for site in craft.app.sites.getEditableSites() %} {% set siteSettings = nav.siteSettings[site.id] ?? null %} {% if siteSettings %} {% for attribute, errors in siteSettings.getErrors() %} {% set siteErrors = siteErrors | merge(errors) %} {% endfor %} {% endif %} {% set siteRows = siteRows | merge({ (site.handle): { heading: site.name | t('site') | e, enabled: isNewNav or (siteSettings.enabled ?? false), } | filter }) %} {% endfor %} {{ forms.editableTableField({ label: 'Site Settings' | t('app'), instructions: 'Choose which sites this navigation should be available in.' | t('navigation'), id: 'sites', name: 'sites', cols: { heading: { type: 'heading', heading: 'Site' | t('app'), thin: true, }, enabled: { type: 'lightswitch', heading: 'Enabled' | t('app'), thin: true, }, } | filter, rows: siteRows, fullWidth: false, allowAdd: false, allowDelete: false, allowReorder: false, errors: siteErrors | unique, }) }} {{ forms.selectField({ label: 'Propagation Method' | t('navigation'), instructions: 'Of the enabled sites above, which sites should nodes in this navigation be saved to?' | t('navigation'), warning: nav.id and nav.propagationMethod != 'none' and nav.siteSettings | length > 1 ? 'Changing this may result in data loss.' | t('navigation'), id: 'propagationMethod', name: 'propagationMethod', options: [ { value: 'none', label: 'Only save nodes to the site they were created in' | t('navigation') }, { value: 'siteGroup', label: 'Save nodes to other sites in the same site group' | t('navigation') }, { value: 'language', label: 'Save nodes to other sites with the same language' | t('navigation') }, { value: 'all', label: 'Save nodes to all sites enabled for this navigation' | t('navigation') }, ], value: nav.propagationMethod, }) }} {% endif %} {{ forms.textField({ label: 'Max Levels' | t('app'), instructions: 'The maximum number of levels this navigation can have. Leave blank for no limit.' | t('navigation'), id: 'maxLevels', name: 'maxLevels', size: 5, value: (nav is defined ? nav.maxLevels : null), errors: (nav is defined ? nav.getErrors('maxLevels') : null), }) }} {{ forms.textField({ label: 'Max Nodes' | t('navigation'), instructions: 'The maximum number of total nodes this navigation can have. Leave blank for no limit.' | t('navigation'), id: 'maxNodes', name: 'maxNodes', size: 5, value: (nav is defined ? nav.maxNodes : null), errors: (nav is defined ? nav.getErrors('maxNodes') : null), }) }} {% set maxNodesSettingsOptions = [] %} {% for i in 1..20 %} {% set maxNodesSettingsOptions = maxNodesSettingsOptions | merge([{ label: 'Level {level}' | t('navigation', { level: i }), value: i, }]) %} {% endfor %} {% set maxNodesSettingsRows = nav.maxNodesSettings %} {% set maxNodesSettingsErrors = nav.getErrors('maxNodesSettings') %} {{ forms.editableTableField({ label: 'Max Nodes per Level' | t('navigation'), instructions: 'Create any level-specific limits for the maximum number of nodes.' | t('navigation'), id: 'maxNodesSettings', name: 'maxNodesSettings', cols: { level: { type: 'select', heading: 'Level' | t('app'), thin: true, options: maxNodesSettingsOptions, }, max: { type: 'number', heading: 'Max Nodes' | t('navigation'), }, } | filter, rows: maxNodesSettingsRows, fullWidth: false, allowAdd: true, allowDelete: true, allowReorder: true, }) }} {{ forms.selectField({ label: 'Default {type} Placement' | t('navigation', { type: 'Node' | t('navigation') }), instructions: 'Where new {type} should be placed by default in the structure.' | t('navigation', { type: 'nodes' | t('navigation') }), id: 'default-placement', name: 'defaultPlacement', options: [ { label: 'Before other {type}' | t('navigation', { type: 'nodes' | t('navigation') }), value: 'beginning'}, { label: 'After other {type}' | t('navigation', { type: 'nodes' | t('navigation') }), value: 'end'}, ], value: nav.defaultPlacement, }) }}
{% endblock %} {% if nav is not defined or not nav.handle %} {% js %} new Craft.HandleGenerator('#name', '#handle'); {% endjs %} {% endif %}