You are here

fieldset.html.twig in Drupal 10

Theme override for a fieldset element and its children.

Available variables:

  • attributes: HTML attributes for the <fieldset> element.
  • errors: (optional) Any errors for this <fieldset> element, may not be set.
  • required: Boolean indicating whether the <fieldset> element is required.
  • legend: The <legend> element containing the following properties:
    • title: Title of the <fieldset>, intended for use as the text of the <legend>.
    • attributes: HTML attributes to apply to the <legend> element.
  • description: The description element containing the following properties:
    • content: The description content of the <fieldset>.
    • attributes: HTML attributes to apply to the description container.
  • description_display: Description display setting. It can have these values:
    • before: The description is output before the element.
    • after: The description is output after the element (default).
    • invisible: The description is output after the element, hidden visually but available to screen readers.
  • children: The rendered child elements of the <fieldset>.
  • prefix: The content to add before the <fieldset> children.
  • suffix: The content to add after the <fieldset> children.
  • title_display: Title display setting.
  • inline_items: Boolean indicating whether the <fieldset> items are inline.

File

core/themes/olivero/templates/form/fieldset.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override for a fieldset element and its children.
  5. *
  6. * Available variables:
  7. * - attributes: HTML attributes for the <fieldset> element.
  8. * - errors: (optional) Any errors for this <fieldset> element, may not be set.
  9. * - required: Boolean indicating whether the <fieldset> element is required.
  10. * - legend: The <legend> element containing the following properties:
  11. * - title: Title of the <fieldset>, intended for use as the text
  12. of the <legend>.
  13. * - attributes: HTML attributes to apply to the <legend> element.
  14. * - description: The description element containing the following properties:
  15. * - content: The description content of the <fieldset>.
  16. * - attributes: HTML attributes to apply to the description container.
  17. * - description_display: Description display setting. It can have these values:
  18. * - before: The description is output before the element.
  19. * - after: The description is output after the element (default).
  20. * - invisible: The description is output after the element, hidden visually
  21. * but available to screen readers.
  22. * - children: The rendered child elements of the <fieldset>.
  23. * - prefix: The content to add before the <fieldset> children.
  24. * - suffix: The content to add after the <fieldset> children.
  25. * - title_display: Title display setting.
  26. * - inline_items: Boolean indicating whether the <fieldset> items are inline.
  27. *
  28. * @see template_preprocess_fieldset()
  29. * @see olivero_preprocess_fieldset()
  30. */
  31. #}
  32. {%
  33. set classes = [
  34. 'fieldset',
  35. attributes.hasClass('fieldgroup') ? 'fieldset--group',
  36. 'js-form-item',
  37. 'form-item',
  38. 'js-form-wrapper',
  39. 'form-wrapper',
  40. ]
  41. %}
  42. {%
  43. set wrapper_classes = [
  44. 'fieldset__wrapper',
  45. attributes.hasClass('fieldgroup') ? 'fieldset__wrapper--group',
  46. ]
  47. %}
  48. {%
  49. set legend_span_classes = [
  50. 'fieldset__label',
  51. attributes.hasClass('fieldgroup') ? 'fieldset__label--group',
  52. required ? 'js-form-required',
  53. required ? 'form-required',
  54. ]
  55. %}
  56. {%
  57. set legend_classes = [
  58. 'fieldset__legend',
  59. attributes.hasClass('fieldgroup') and not attributes.hasClass('form-composite') ? 'fieldset__legend--group',
  60. attributes.hasClass('form-composite') ? 'fieldset__legend--composite',
  61. title_display == 'invisible' ? 'fieldset__legend--invisible' : 'fieldset__legend--visible',
  62. ]
  63. %}
  64. {%
  65. set description_classes = [
  66. 'fieldset__description',
  67. ]
  68. %}
  69. <fieldset{{ attributes.addClass(classes) }}>
  70. {# Always wrap fieldset legends in a <span> for CSS positioning. #}
  71. {% if legend.title %}
  72. <legend{{ legend.attributes.addClass(legend_classes) }}>
  73. <span{{ legend_span.attributes.addClass(legend_span_classes) }}>{{ legend.title }}</span>
  74. </legend>
  75. {% endif %}
  76. <div{{ content_attributes.addClass(wrapper_classes) }}>
  77. {% if inline_items %}
  78. <div class="container-inline">
  79. {% endif %}
  80. {% if description_display == 'before' and description.content %}
  81. <div{{ description.attributes.addClass(description_classes) }}>{{ description.content }}</div>
  82. {% endif %}
  83. {% if prefix %}
  84. <span class="fieldset__prefix">{{ prefix }}</span>
  85. {% endif %}
  86. {{ children }}
  87. {% if suffix %}
  88. <span class="fieldset__suffix">{{ suffix }}</span>
  89. {% endif %}
  90. {% if errors %}
  91. <div class="fieldset__error-message">
  92. {{ errors }}
  93. </div>
  94. {% endif %}
  95. {% if description_display in ['after', 'invisible'] and description.content %}
  96. <div{{ description.attributes.addClass(description_classes) }}>{{ description.content }}</div>
  97. {% endif %}
  98. {% if inline_items %}
  99. </div>
  100. {% endif %}
  101. </div>
  102. </fieldset>