{% requireAdmin %} {% extends "_layouts/cp" %} {% set title = "Fields"|t('app') %} {% do view.registerAssetBundle("craft\\web\\assets\\fields\\FieldsAsset") %} {% do view.registerAssetBundle('craft\\web\\assets\\admintable\\AdminTableAsset') -%} {% do view.registerTranslations('app', [ "What do you want to name the group?", "Could not create the group:", "Could not create the group:", "Are you sure you want to delete this group and all its fields?", "Could not delete the group.", "Group renamed.", "Name", "Handle", "Type", "Group", "This field’s values are used as search keywords.", "This group doesn’t have any fields yet.", "No fields exist yet.", ]) %} {% set crumbs = [ { label: "Settings"|t('app'), url: url('settings') } ] %} {% set groups = craft.app.fields.getAllGroups()|index('id') %} {% if groupId is defined %} {% if groups[groupId] is not defined %} {% exit 404 %} {% endif %} {% set fields = groups[groupId].getFields() %} {% set emptyMessage = "This group doesn’t have any fields yet."|t('app') %} {% else %} {% set emptyMessage = "No fields exist yet."|t('app') %} {% set fields = craft.app.fields.getAllFields() %} {% endif %} {% block actionButton %} {% if groups %} {% set newFieldUrl = url('settings/fields/new', (groupId is defined ? { groupId: groupId } : null)) %} {{ "New field"|t('app') }} {% endif %} {% endblock %} {% block sidebar %}
{% if groupId is defined %} {% endif %}
{% endblock %} {% block content %}
{% endblock %} {% set tableData = [] %} {% for field in fields %} {% set fieldIsMissing = false %} {% if field is missing %} {% set fieldIsMissing = true %} {% endif %} {% set group = field.getGroup() %} {% set tableData = tableData|merge([{ id: field.id, title: field.name|t('site'), translatable: field.getIsTranslatable() ? (field.getTranslationDescription() ?? 'This field is translatable.'|t('app')), searchable: field.searchable ? true : false, url: url('settings/fields/edit/' ~ field.id), handle: field.handle, type: { isMissing: fieldIsMissing, label: fieldIsMissing ? field.expectedType : field.displayName() }, group: group ? group.name|t('site')|e : "#{'(Ungrouped)'|t('app')}", }]) %} {% endfor %} {% js %} var columns = [ { name: '__slot:title', title: Craft.t('app', 'Name') }, { name: 'searchable', titleClass: 'thin', callback: value => { if (!value) { return null; } return ``; } }, {% if craft.app.isMultiSite %} { name: 'translatable', titleClass: 'thin', callback: value => { if (!value) { return null; } return ``; } }, {% endif %} { name: '__slot:handle', title: Craft.t('app', 'Handle') }, { name: 'type', title: Craft.t('app', 'Type'), callback: function(value) { if (value.isMissing) { return '' + value.label + '' } return value.label } }, ]; {% if groupId is not defined %} columns.push({ name: 'group', title: Craft.t('app', 'Group'), }) {% endif %} new Craft.VueAdminTable({ columns: columns, container: '#fields-vue-admin-table', deleteAction: 'fields/delete-field', emptyMessage: Craft.t('app', '{{ emptyMessage }}'), tableData: {{ tableData|json_encode|raw }}, }); {% endjs %}