{% from 'neo/macros' import getBlockId %} {% set neoSettings = craft.app.plugins.getPlugin('neo').settings %} {% set type = block.type %} {% set typeTabs = type.getFieldLayout().getTabs() %} {% set typeName = type.name|t('site') %} {% set hasTabs = typeTabs is not empty %} {% set isParent = static and block.children.exists() or not static and type.childBlocks is not null and type.childBlocks is not empty %} {% set collapsed = collapsed ?? (neoSettings.collapseAllBlocks or block.collapsed) %} {% set blockId = getBlockId(block) %} {% set isNew = block.id is null %} {% set hasErrors = block.hasErrors() %} {% set showFormAndTabs = hasTabs or isParent %} {% set renderedForm = null %} {% set formTabs = null %} {% set visibleLayoutElements = {} %} {% set ignorePermissions = not neoSettings.enableBlockTypeUserPermissions or type.ignorePermissions %} {# Get the errors specific to the block (i.e. not subfield errors) #} {% set blockErrors = [] %} {% for attribute, errors in block.getErrors() %} {% if attribute[:5] == '__NEO' %} {% set blockErrors = blockErrors|merge(errors) %} {% endif %} {% endfor %} {% set errorList -%} {%- if blockErrors is not empty %}
{% include '_includes/forms/errorList' with { errors: blockErrors } %}
{% endif -%} {%- endset %} {% set baseInputName = "#{handle}[blocks][#{blockId}]" %} {% set blockAttributes = { class: [ 'ni_block', "ni_block--#{type.handle}", collapsed ? 'is-collapsed' : 'is-expanded', not hasTabs and not isParent ? 'is-empty', isParent ? 'is-parent', hasErrors ? 'has-errors', neoSettings.enableBlockTypeUserPermissions and not type.ignorePermissions and not currentUser.can("neo-editBlocks:#{type.uid}") ? 'is-disabled-for-user', ], data: { 'neo-b-id': blockId, 'neo-b-name': "#{typeName}", }, } %} {% set actionBtnLabel = "#{typeName} #{'Actions'|t('neo')}" %} {% set actionMenuId = "neoblock-action-menu-#{blockId}" %} {% set actionBtnAttributes = { class: ['btn', 'settings', 'icon', 'menubtn'], type: 'button', role: 'button', title: 'Actions'|t('neo'), aria: { controls: actionMenuId, label: actionBtnLabel, }, data: { 'disclosure-trigger': true, 'neo-b': "#{blockId}.button.actions", }, } %} {# If this block either has tabs or is a parent, get the form HTML now #} {# Done like this so we can: #} {# 1. use `createForm()` without repeatedly namespacing the child blocks #} {# 2. get the form tabs at the same time #} {% if showFormAndTabs %} {% set renderedForm %} {% namespace baseInputName %} {% set layoutForm = block.getFieldLayout().createForm(block, static) %} {% set formTabs = layoutForm.tabs %} {% set visibleLayoutElements = layoutForm.getVisibleElements() %} {{ layoutForm.render()|raw }} {% endnamespace %} {% endset %} {% endif %} {% set blockTypeHandleLabel %}{% if currentUser.getPreference('showFieldHandles') %}
{% include '_includes/forms/copytextbtn' with { id: "#{handle}-blocks-#{blockId}-#{type.handle}-attribute", class: ['code', 'small', 'light'], value: type.handle, } %}
{% endif %}{% endset %}
{{ hiddenInput("#{baseInputName}[type]", type.handle, {'data-neo-b': blockId ~ '.input.type'}) }} {{ hiddenInput("#{baseInputName}[enabled]", block.enabled ? '1' : '', {'data-neo-b': blockId ~ '.input.enabled'}) }} {{ hiddenInput("#{baseInputName}[level]", block.level, {'data-neo-b': blockId ~ '.input.level'}) }} {{ hiddenInput("#{handle}[sortOrder][]", blockId, {'data-neo-b': blockId ~ '.input.sortOrder'}) }} {% if isFresh ?? false %} {{ hiddenInput("#{baseInputName}[fresh]", '1') }} {% endif %} {% if not isNew %} {% do view.registerDeltaName(baseInputName) %} {% endif %}
{{ typeName }}{# #}{% if block.hasErrors() %}{% endif %}
{{ blockTypeHandleLabel }}
 
{% if showFormAndTabs %}
{% include 'neo/_tabs' with { tabs: formTabs, block, blockId, } only %} {% endif %}
{% if showFormAndTabs %}
{% if hasTabs %}
{# Replace the form HTML's child blocks UI element placeholder with actual child blocks #} {% set splitOnChildBlocks = renderedForm|split('
', 2) %} {% include 'neo/child-blocks' with { block, handle, static, uid: splitAfterChildBlocks[0] } %} {{ errorList }} {{ splitAfterChildBlocks[1]|raw }} {% endif %}
{% endif %} {% if isParent and not type.hasChildBlocksUiElement() %}
{% for child in block.children.status(null).all() %} {% include 'neo/block' with { handle, block: child, static } only %} {% endfor %}
{% if not static %} {% endif %}
{{ errorList }} {% endif %}
{% endif %} {% if isParent %}
{% endif %}
{% js %} Garnish.on(Neo.Input, 'afterInit', (e) => { if (e.target.getName() === '{{ handle }}') { e.target.setVisibleElements({{ isNew ? "'#{blockId}'"|raw : blockId }}, '{{ visibleLayoutElements|json_encode|raw }}') } }) {% endjs %}