editor.html.twig 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. {% set value = (value is null ? field.default|tu : value) %}
  2. {% if not codemirrorOptions %}
  3. {% set codemirrorOptions = {'mode': 'gfm', 'ignore': ['code', 'preview']}|merge(field.codemirror|default({})) %}
  4. {% endif %}
  5. {% block label %}
  6. {% if field.label %}
  7. {% set hint = field.help ? 'data-hint="' ~ field.help|tu|raw ~ '"': '' %}
  8. <div class="form-label form-field hint--bottom" {{ hint }}>{{ field.label|tu|raw }}</div>
  9. {% endif %}
  10. {% endblock %}
  11. {% block field %}
  12. <div class="form-field {{ field.classes|default('') }}">
  13. <div class="form-data grav-editor">
  14. <div class="grav-editor-content is-active">
  15. <textarea
  16. data-grav-editor="{{ {'codemirror': codemirrorOptions} | json_encode|e('html_attr') }}"
  17. data-grav-editor-mode="editor"
  18. name="{{ (scope ~ field.name)|fieldName }}"
  19. {% if field.classes is defined %}class="{{ field.classes }}" {% endif %}
  20. {% if field.id is defined %}id="{{ field.id|e }}" {% endif %}
  21. {% if field.style is defined %}style="{{ field.style|e }}" {% endif %}
  22. {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}
  23. {% if field.placeholder %}placeholder="{{ field.placeholder|tu }}"{% endif %}
  24. {% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
  25. {% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
  26. {% if field.readonly in ['on', 'true', 1] %}readonly="readonly"{% endif %}
  27. {% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %}
  28. {% if 'preview' not in codemirrorOptions.ignore %}data-grav-urlpreview="{{ base_url }}/media/{{ admin.route|trim('/') }}.json"{% endif %}
  29. >{{ value|join("\n")|e('html') }}</textarea>
  30. </div>
  31. {% if field.resizer is not defined or field.resizer not in ['off', 'false', 0] %}<div class="grav-editor-resizer"></div>{% endif %}
  32. {% if field.description %}
  33. <div class="form-extra-wrapper {{ field.size }} {{ field.wrapper_classes }}">
  34. <span class="form-description">
  35. {% if field.markdown %}
  36. {{ field.description|tu|markdown(false)|raw }}
  37. {% else %}
  38. {{ field.description|tu|raw }}
  39. {% endif %}
  40. </span>
  41. </div>
  42. {% endif %}
  43. </div>
  44. </div>
  45. {% endblock %}