Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x

form-element.html.twig

Same filename in this branch
  1. 11.1.x core/profiles/demo_umami/themes/umami/templates/classy/form/form-element.html.twig
  2. 11.1.x core/themes/stable9/templates/form/form-element.html.twig
  3. 11.1.x core/themes/starterkit_theme/templates/form/form-element.html.twig
  4. 11.1.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>

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal