checkboxes.html.twig 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. {% extends "forms/field.html.twig" %}
  2. {% set originalValue = value %}
  3. {% set value = (value is null ? field.default : value) %}
  4. {% if field.use == 'keys' and field.default %}
  5. {% set value = field.default|merge(value) %}
  6. {% endif %}
  7. {% block global_attributes %}
  8. {{ parent() }}
  9. data-grav-keys="{{ field.use == 'keys' ? 'true' : 'false' }}"
  10. data-grav-field-name="{{ (scope ~ field.name)|fieldName }}"
  11. {% endblock %}
  12. {% block input %}
  13. {% for key, text in field.options %}
  14. {% set id = field.id|default(field.name) ~ '-' ~ key %}
  15. {% set name = field.use == 'keys' ? key : id %}
  16. {% set val = field.use == 'keys' ? '1' : key %}
  17. {% set checked = (field.use == 'keys' ? value[key] : key in value) %}
  18. {% set help = (key in field.help_options|keys ? field.help_options[key] : false) %}
  19. <div class="checkboxes {{ form_field_wrapper_classes }} {{ field.wrapper_classes }}">
  20. <label class="{{ form_field_checkbox_classes }}" for="{{ id|e }}">
  21. <input type="checkbox"
  22. id="{{ id|e }}"
  23. value="{{ val|e }}"
  24. name="{{ (scope ~ field.name)|fieldName ~ '[' ~ name ~ ']' }}"
  25. {% if checked %}checked="checked"{% endif %}
  26. {% if field.classes is defined %}class="{{ field.classes }}" {% endif %}
  27. {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}
  28. >
  29. <i class="form-icon"></i>
  30. {% if help %}
  31. <span class="hint--bottom" data-hint="{{ help|t|e('html_attr') }}">{{ text|t|e }}</span>
  32. {% else %}
  33. {{ text|t|e }}
  34. {% endif %}
  35. </label>
  36. </div>
  37. {% endfor %}
  38. {% endblock %}