field.html.twig 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. {% set originalValue = originalValue is defined ? originalValue : value %}
  2. {% set toggleableChecked = field.toggleable and (originalValue is not null and originalValue is not empty) %}
  3. {% set isDisabledToggleable = field.toggleable and not toggleableChecked %}
  4. {% set value = (value is null ? field.default : value) %}
  5. {% set vertical = field.style == 'vertical' %}
  6. {% set field_name = (scope ~ field.name)|fieldName %}
  7. {% if (field.yaml or field.validate.type == 'yaml') and value is iterable%}
  8. {% set value = value|toYaml %}
  9. {% endif %}
  10. {% block field %}
  11. <div class="form-field grid{% if vertical %} vertical{% endif %}{% if field.toggleable %} form-field-toggleable{% endif %} {{ field.outerclasses }} {{ field.field_classes }}">
  12. {% block contents %}
  13. <div class="form-label{% if not vertical %} block size-1-3{% endif %}">
  14. {% if field.toggleable %}
  15. <span class="checkboxes toggleable" data-grav-field="toggleable" data-grav-field-name="{{ field_name }}">
  16. <input type="checkbox"
  17. id="toggleable_{{ field.name }}"
  18. {% if toggleableChecked %}value="1"{% endif %}
  19. name="toggleable_{{ field_name }}"
  20. {% if toggleableChecked %}checked="checked"{% endif %}
  21. >
  22. <label for="toggleable_{{ field.name }}"></label>
  23. </span>
  24. {% endif %}
  25. <label{{ (field.toggleable ? ' class="toggleable" for="toggleable_' ~ field.name ~ '"')|raw }}>
  26. {% block label %}
  27. {% if field.help %}
  28. {% if field.markdown %}
  29. <span class="hint--bottom" data-hint="{{ field.help|tu|markdown(false)|e('html') }}">{{ field.label|tu|markdown(false)|raw }}</span>
  30. {% else %}
  31. <span class="hint--bottom" data-hint="{{ field.help|tu|e('html') }}">{{ field.label|tu|raw }}</span>
  32. {% endif %}
  33. {% else %}
  34. {% if field.markdown %}
  35. {{ field.label|tu|markdown(false)|raw }}
  36. {% else %}
  37. {{ field.label|tu|raw }}
  38. {% endif %}
  39. {% endif %}
  40. {{ field.validate.required in ['on', 'true', 1] ? '<span class="required">*</span>' }}
  41. {% endblock %}
  42. </label>
  43. {% if field.sublabel %}
  44. <div class="form-sublabel">
  45. {% if field.markdown %}
  46. {{ field.sublabel|tu|markdown(false)|raw }}
  47. {% else %}
  48. {{ field.sublabel|tu|raw }}
  49. {% endif %}
  50. </div>
  51. {% endif %}
  52. </div>
  53. <div class="form-data{% if not vertical %} block size-2-3{% endif %}"
  54. {% block global_attributes %}
  55. data-grav-field="{{ field.type }}"
  56. data-grav-disabled="{{ toggleableChecked }}"
  57. data-grav-default="{{ field.default|json_encode|e('html_attr') }}"
  58. {% endblock %}
  59. >
  60. {% block group %}
  61. {% block input %}
  62. <div class="form-input-wrapper {{ field.size }} {{ field.wrapper_classes }}">
  63. {% block prepend %}{% endblock prepend %}
  64. <input
  65. {# required attribute structures #}
  66. name="{{ field_name }}"
  67. value="{{ value|join(', ') }}"
  68. {% if field.key %}
  69. data-key-observe="{{ (scope ~ field_name)|fieldName }}"
  70. {% endif %}
  71. {# input attribute structures #}
  72. {% block input_attributes %}
  73. {% if field.classes is defined %}class="{{ field.classes }}" {% endif %}
  74. {% if field.id is defined %}id="{{ field.id|e }}" {% endif %}
  75. {% if field.style is defined %}style="{{ field.style|e }}" {% endif %}
  76. {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}
  77. {% if field.placeholder %}placeholder="{{ field.placeholder|tu }}"{% endif %}
  78. {% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
  79. {% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
  80. {% if field.readonly in ['on', 'true', 1] %}readonly="readonly"{% endif %}
  81. {% if field.autocomplete in ['on', 'off', 'new-password'] %}autocomplete="{{ field.autocomplete }}"{% endif %}
  82. {% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %}
  83. {% if field.validate.pattern %}pattern="{{ field.validate.pattern }}"{% endif %}
  84. {% if field.validate.message %}title="{{ field.validate.message|e|tu }}"
  85. {% elseif field.title is defined %}title="{{ field.title|e|tu }}" {% endif %}
  86. {% endblock %}
  87. />
  88. {% block append %}{% endblock append %}
  89. </div>
  90. {% endblock %}
  91. {% endblock %}
  92. {% if field.description %}
  93. <div class="form-extra-wrapper {{ field.size }} {{ field.wrapper_classes }}">
  94. <span class="form-description">
  95. {% if field.markdown %}
  96. {{ field.description|tu|markdown(false)|raw }}
  97. {% else %}
  98. {{ field.description|tu|raw }}
  99. {% endif %}
  100. </span>
  101. </div>
  102. {% endif %}
  103. </div>
  104. {% endblock %}
  105. </div>
  106. {% endblock %}