You are here

form-element--rating.html.twig in Rate 8.2

Default theme implementation for a form element.

Available variables:

  • attributes: HTML attributes for the containing element.
  • errors: (optional) Any inline error messages to display for this form element; may not be set.
  • required: The required marker, or empty if the associated form element is not required.
  • type: The type of the element.
  • name: The name of the element.
  • label: A rendered label element.
  • label_display: Label display setting. It can have these values:
    • before: The label is output before the element. This is the default. The label includes the #title and the required marker, if #required.
    • after: The label is output after the element. For example, this is used for radio and checkbox #type elements. If the #title is empty but the field is #required, the label will contain only the required marker.
    • invisible: Labels are critical for screen readers to enable them to properly navigate through forms but can be visually distracting. This property hides the label for everyone except screen readers.
    • attribute: Set the title attribute on the element to create a tooltip but output no label element. This is supported only for checkboxes and radios in \Drupal\Core\Render\Element\CompositeFormElementTrait::preRenderCompositeFormElement(). It is used where a visual label is not needed, such as a table of checkboxes where the row and column provide the context. The tooltip will include the title and required marker.
  • description: (optional) A list of description properties containing:
    • content: A description of the form element, may not be set.
    • attributes: (optional) A list of HTML attributes to apply to the description content wrapper. Will only be set when description is set.
  • 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. This is the default value.
    • invisible: The description is output after the element, hidden visually but available to screen readers.
  • disabled: True if the element is disabled.
  • title_display: Title display setting.

File

templates/form-element--rating.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation for a form element.
  5. *
  6. * Available variables:
  7. * - attributes: HTML attributes for the containing element.
  8. * - errors: (optional) Any inline error messages to display for this form
  9. * element; may not be set.
  10. * - required: The required marker, or empty if the associated form element is
  11. * not required.
  12. * - type: The type of the element.
  13. * - name: The name of the element.
  14. * - label: A rendered label element.
  15. * - label_display: Label display setting. It can have these values:
  16. * - before: The label is output before the element. This is the default.
  17. * The label includes the #title and the required marker, if #required.
  18. * - after: The label is output after the element. For example, this is used
  19. * for radio and checkbox #type elements. If the #title is empty but the
  20. * field is #required, the label will contain only the required marker.
  21. * - invisible: Labels are critical for screen readers to enable them to
  22. * properly navigate through forms but can be visually distracting. This
  23. * property hides the label for everyone except screen readers.
  24. * - attribute: Set the title attribute on the element to create a tooltip but
  25. * output no label element. This is supported only for checkboxes and radios
  26. * in \Drupal\Core\Render\Element\CompositeFormElementTrait::preRenderCompositeFormElement().
  27. * It is used where a visual label is not needed, such as a table of
  28. * checkboxes where the row and column provide the context. The tooltip will
  29. * include the title and required marker.
  30. * - description: (optional) A list of description properties containing:
  31. * - content: A description of the form element, may not be set.
  32. * - attributes: (optional) A list of HTML attributes to apply to the
  33. * description content wrapper. Will only be set when description is set.
  34. * - description_display: Description display setting. It can have these values:
  35. * - before: The description is output before the element.
  36. * - after: The description is output after the element. This is the default
  37. * value.
  38. * - invisible: The description is output after the element, hidden visually
  39. * but available to screen readers.
  40. * - disabled: True if the element is disabled.
  41. * - title_display: Title display setting.
  42. *
  43. * @ingroup templates
  44. *
  45. * @see template_preprocess_form_element()
  46. */
  47. #}
  48. {%
  49. set classes = [
  50. 'form-item',
  51. 'js-form-item',
  52. 'form-type-' ~ type|clean_class,
  53. 'js-form-type-' ~ type|clean_class,
  54. 'form-item-' ~ name|clean_class,
  55. 'js-form-item-' ~ name|clean_class,
  56. title_display not in ['after', 'before'] ? 'form-no-label',
  57. disabled == 'disabled' ? 'form-disabled',
  58. is_form_group ? 'form-group',
  59. is_checkbox ? 'checkbox',
  60. is_autocomplete ? 'form-autocomplete',
  61. has_error ? 'error has-error'
  62. ]
  63. %}
  64. <div{{ attributes.addClass(classes) }}>
  65. <label{{ attributes.addClass(label_attributes.class)}}>{{ children }}{{ title }}
  66. </label>
  67. {% if option_result is not empty %}
  68. <div class="rating-option-result">{{ option_result }}</div>
  69. {% endif %}
  70. {% if errors %}
  71. <div class="form-item--error-message">
  72. <strong>{{ errors }}</strong>
  73. </div>
  74. {% endif %}
  75. </div>