form-element.html.twig

Same filename in this branch
  1. 10 core/profiles/demo_umami/themes/umami/templates/classy/form/form-element.html.twig
  2. 10 core/themes/stable9/templates/form/form-element.html.twig
  3. 10 core/themes/starterkit_theme/templates/form/form-element.html.twig
  4. 10 core/modules/system/templates/form-element.html.twig
Same filename in other branches
  1. 9 core/profiles/demo_umami/themes/umami/templates/classy/form/form-element.html.twig
  2. 9 core/themes/stable9/templates/form/form-element.html.twig
  3. 9 core/themes/seven/templates/classy/form/form-element.html.twig
  4. 9 core/themes/claro/templates/form-element.html.twig
  5. 9 core/themes/bartik/templates/classy/form/form-element.html.twig
  6. 9 core/themes/stable/templates/form/form-element.html.twig
  7. 9 core/themes/starterkit_theme/templates/form/form-element.html.twig
  8. 9 core/themes/classy/templates/form/form-element.html.twig
  9. 9 core/modules/system/templates/form-element.html.twig
  10. 8.9.x core/profiles/demo_umami/themes/umami/templates/classy/form/form-element.html.twig
  11. 8.9.x core/themes/seven/templates/classy/form/form-element.html.twig
  12. 8.9.x core/themes/claro/templates/form-element.html.twig
  13. 8.9.x core/themes/bartik/templates/classy/form/form-element.html.twig
  14. 8.9.x core/themes/stable/templates/form/form-element.html.twig
  15. 8.9.x core/themes/classy/templates/form/form-element.html.twig
  16. 8.9.x core/modules/system/templates/form-element.html.twig
  17. 11.x core/profiles/demo_umami/themes/umami/templates/classy/form/form-element.html.twig
  18. 11.x core/themes/stable9/templates/form/form-element.html.twig
  19. 11.x core/themes/claro/templates/form-element.html.twig
  20. 11.x core/themes/starterkit_theme/templates/form/form-element.html.twig
  21. 11.x core/modules/system/templates/form-element.html.twig

Theme override for a form element.

See also

template_preprocess_form_element()

File

core/themes/claro/templates/form-element.html.twig

View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override for a form element.
  5. *
  6. * @see template_preprocess_form_element()
  7. */
  8. #}
  9. {#
  10. Most of core-provided js assumes that the CSS class pattern js-form-item-[something] or
  11. js-form-type-[something] exists on form items. We have to keep them.
  12. #}
  13. {%
  14. set classes = [
  15. 'js-form-item',
  16. 'form-item',
  17. 'js-form-type-' ~ type|clean_class,
  18. 'form-type--' ~ type|clean_class,
  19. type in ['checkbox', 'radio'] ? 'form-type--boolean',
  20. 'js-form-item-' ~ name|clean_class,
  21. 'form-item--' ~ name|clean_class,
  22. title_display not in ['after', 'before'] ? 'form-item--no-label',
  23. disabled == 'disabled' ? 'form-item--disabled',
  24. errors ? 'form-item--error',
  25. ]
  26. %}
  27. {%
  28. set description_classes = [
  29. 'form-item__description',
  30. description_display == 'invisible' ? 'visually-hidden',
  31. ]
  32. %}
  33. <div{{ attributes.addClass(classes) }}>
  34. {% if label_display in ['before', 'invisible'] %}
  35. {{ label }}
  36. {% endif %}
  37. {% if prefix is not empty %}
  38. <span class="form-item__prefix{{ disabled == 'disabled' ? ' is-disabled' }}">{{ prefix }}</span>
  39. {% endif %}
  40. {% if description_display == 'before' and description.content %}
  41. <div{{ description.attributes.addClass(description_classes) }}>
  42. {{ description.content }}
  43. </div>
  44. {% endif %}
  45. {{ children }}
  46. {% if suffix is not empty %}
  47. <span class="form-item__suffix{{ disabled == 'disabled' ? ' is-disabled' }}">{{ suffix }}</span>
  48. {% endif %}
  49. {% if label_display == 'after' %}
  50. {{ label }}
  51. {% endif %}
  52. {% if errors %}
  53. <div class="form-item__error-message">
  54. {{ errors }}
  55. </div>
  56. {% endif %}
  57. {% if description_display in ['after', 'invisible'] and description.content %}
  58. <div{{ description.attributes.addClass(description_classes) }}>
  59. {{ description.content }}
  60. </div>
  61. {% endif %}
  62. </div>

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.