{% extends "forms/field.html.twig" %} {% macro spanToggle(input, length) %} {% set space = repeat('  ', (length - input|length) / 2) %} {{ (space ~ input ~ space)|raw }} {% endmacro %} {% macro section(section, context, depth) %} {% import _self as macro %} {% set section_label = (section.label ?? section.name)|t %} {# Sub sections can have top-level toggle.. needs to #} {% if depth > 0 %} {% set section_value = context.access.get(section.name)|string %} {% set params = { context: context, action_label: section_label, action_value: section_value, action_name: section.name, action_class: 'parent-section' } %} {{ macro.action_row(params) }} {% endif %}
{% if depth == 0 %} {{ section_label }} {% endif %} {% for action in section %} {% if action.visible %} {% if action.count %} {{ macro.section(action, context, depth + 1) }} {% else %} {{ macro.action(action, context) }} {% endif %} {% endif %} {% endfor %}
{% endmacro %} {% macro action(action, context) %} {% import _self as macro %} {% set action_label = action.label ?? action.name %} {% set action_value = context.access.get(action.name)|string %} {% set params = { context: context, action_label: action_label, action_value: action_value, action_name: action.name, action_parent: action.getParent().name } %} {{ macro.action_row(params) }} {% endmacro %} {% macro action_row(data) %} {% import _self as macro %} {% set context = data.context %} {% set field = context.field %}
{{ data.action_label|t }} {% if context.auth_badges %} {% set auth = context.object.authorize(data.action_name, 'test') ?? context.super %} {% if context.super and auth %} {% elseif auth %} {% else %} {% endif %} {% endif %}
{% for key, text in context.options %} {% set parent_id = data.action_parent ? "toggle_" ~ field.name ~ "." ~ data.action_parent %} {% set id = "toggle_" ~ field.name ~ "." ~ data.action_name ~ key %} {% set translation = text|t|trim %} {% endfor %}
{% endmacro %} {% import _self as macro %} {% block global_attributes %} data-grav-disabled="{{ originalValue is null ? 'true' : 'false' }}" data-grav-default="{{ field.default|json_encode()|e('html_attr') }}" {% endblock %} {% block input %} {% set options = { '1': 'PLUGIN_ADMIN.ALLOWED', '0': 'PLUGIN_ADMIN.DENIED', '': 'PLUGIN_ADMIN.NOT_SET' } %} {% set maxLen = 0 %} {% for text in options %} {% set maxLen = max(text|t|trim|length, maxLen) %} {% endfor %} {% set permissions = grav.permissions %} {% set access = permissions.access(value) %} {% if object and field.check_authorize %} {% set auth_badges = true %} {% set super = object.authorize('admin.super', 'test') %} {% endif %}
{% for section in permissions %} {% if section.count %} {{ macro.section(section, _context, 0) }} {% endif %} {% endfor %} {# Look for missing actions #} {% set unknown %} {% for key,val in access.getAllActions() %} {% if not permissions.getAction(key) %} {{ macro.action({name: key}, _context) }} {% endif %} {% endfor %} {% endset %} {% if unknown|trim %}
Unknown Permissions {{ unknown|raw }}
{% endif %}
{% endblock %}