Chris@0: {# Chris@0: /** Chris@0: * @file Chris@0: * Default theme implementation for a form element. Chris@0: * Chris@0: * Available variables: Chris@0: * - attributes: HTML attributes for the containing element. Chris@0: * - errors: (optional) Any errors for this form element, may not be set. Chris@0: * - prefix: (optional) The form element prefix, may not be set. Chris@0: * - suffix: (optional) The form element suffix, may not be set. Chris@0: * - required: The required marker, or empty if the associated form element is Chris@0: * not required. Chris@0: * - type: The type of the element. Chris@0: * - name: The name of the element. Chris@0: * - label: A rendered label element. Chris@0: * - label_display: Label display setting. It can have these values: Chris@0: * - before: The label is output before the element. This is the default. Chris@0: * The label includes the #title and the required marker, if #required. Chris@0: * - after: The label is output after the element. For example, this is used Chris@0: * for radio and checkbox #type elements. If the #title is empty but the Chris@0: * field is #required, the label will contain only the required marker. Chris@0: * - invisible: Labels are critical for screen readers to enable them to Chris@0: * properly navigate through forms but can be visually distracting. This Chris@0: * property hides the label for everyone except screen readers. Chris@0: * - attribute: Set the title attribute on the element to create a tooltip but Chris@0: * output no label element. This is supported only for checkboxes and radios Chris@0: * in \Drupal\Core\Render\Element\CompositeFormElementTrait::preRenderCompositeFormElement(). Chris@0: * It is used where a visual label is not needed, such as a table of Chris@0: * checkboxes where the row and column provide the context. The tooltip will Chris@0: * include the title and required marker. Chris@0: * - description: (optional) A list of description properties containing: Chris@0: * - content: A description of the form element, may not be set. Chris@0: * - attributes: (optional) A list of HTML attributes to apply to the Chris@0: * description content wrapper. Will only be set when description is set. Chris@0: * - description_display: Description display setting. It can have these values: Chris@0: * - before: The description is output before the element. Chris@0: * - after: The description is output after the element. This is the default Chris@0: * value. Chris@0: * - invisible: The description is output after the element, hidden visually Chris@0: * but available to screen readers. Chris@0: * - disabled: True if the element is disabled. Chris@0: * - title_display: Title display setting. Chris@0: * Chris@0: * @see template_preprocess_form_element() Chris@0: * Chris@0: * @ingroup themeable Chris@0: */ Chris@0: #} Chris@0: {% Chris@0: set classes = [ Chris@0: 'js-form-item', Chris@0: 'form-item', Chris@0: 'js-form-type-' ~ type|clean_class, Chris@0: 'form-item-' ~ name|clean_class, Chris@0: 'js-form-item-' ~ name|clean_class, Chris@0: title_display not in ['after', 'before'] ? 'form-no-label', Chris@0: disabled == 'disabled' ? 'form-disabled', Chris@0: errors ? 'form-item--error', Chris@0: ] Chris@0: %} Chris@0: {% Chris@0: set description_classes = [ Chris@0: 'description', Chris@0: description_display == 'invisible' ? 'visually-hidden', Chris@0: ] Chris@0: %} Chris@0: Chris@0: {% if label_display in ['before', 'invisible'] %} Chris@0: {{ label }} Chris@0: {% endif %} Chris@0: {% if prefix is not empty %} Chris@0: {{ prefix }} Chris@0: {% endif %} Chris@0: {% if description_display == 'before' and description.content %} Chris@0: Chris@0: {{ description.content }} Chris@0: Chris@0: {% endif %} Chris@0: {{ children }} Chris@0: {% if suffix is not empty %} Chris@0: {{ suffix }} Chris@0: {% endif %} Chris@0: {% if label_display == 'after' %} Chris@0: {{ label }} Chris@0: {% endif %} Chris@0: {% if errors %} Chris@0:
Chris@0: {{ errors }} Chris@0:
Chris@0: {% endif %} Chris@0: {% if description_display in ['after', 'invisible'] and description.content %} Chris@0: Chris@0: {{ description.content }} Chris@0: Chris@0: {% endif %} Chris@0: