annotate core/modules/system/templates/form-element.html.twig @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 {#
Chris@0 2 /**
Chris@0 3 * @file
Chris@0 4 * Default theme implementation for a form element.
Chris@0 5 *
Chris@0 6 * Available variables:
Chris@0 7 * - attributes: HTML attributes for the containing element.
Chris@0 8 * - errors: (optional) Any errors for this form element, may not be set.
Chris@0 9 * - prefix: (optional) The form element prefix, may not be set.
Chris@0 10 * - suffix: (optional) The form element suffix, may not be set.
Chris@0 11 * - required: The required marker, or empty if the associated form element is
Chris@0 12 * not required.
Chris@0 13 * - type: The type of the element.
Chris@0 14 * - name: The name of the element.
Chris@0 15 * - label: A rendered label element.
Chris@0 16 * - label_display: Label display setting. It can have these values:
Chris@0 17 * - before: The label is output before the element. This is the default.
Chris@0 18 * The label includes the #title and the required marker, if #required.
Chris@0 19 * - after: The label is output after the element. For example, this is used
Chris@0 20 * for radio and checkbox #type elements. If the #title is empty but the
Chris@0 21 * field is #required, the label will contain only the required marker.
Chris@0 22 * - invisible: Labels are critical for screen readers to enable them to
Chris@0 23 * properly navigate through forms but can be visually distracting. This
Chris@0 24 * property hides the label for everyone except screen readers.
Chris@0 25 * - attribute: Set the title attribute on the element to create a tooltip but
Chris@0 26 * output no label element. This is supported only for checkboxes and radios
Chris@0 27 * in \Drupal\Core\Render\Element\CompositeFormElementTrait::preRenderCompositeFormElement().
Chris@0 28 * It is used where a visual label is not needed, such as a table of
Chris@0 29 * checkboxes where the row and column provide the context. The tooltip will
Chris@0 30 * include the title and required marker.
Chris@0 31 * - description: (optional) A list of description properties containing:
Chris@0 32 * - content: A description of the form element, may not be set.
Chris@0 33 * - attributes: (optional) A list of HTML attributes to apply to the
Chris@0 34 * description content wrapper. Will only be set when description is set.
Chris@0 35 * - description_display: Description display setting. It can have these values:
Chris@0 36 * - before: The description is output before the element.
Chris@0 37 * - after: The description is output after the element. This is the default
Chris@0 38 * value.
Chris@0 39 * - invisible: The description is output after the element, hidden visually
Chris@0 40 * but available to screen readers.
Chris@0 41 * - disabled: True if the element is disabled.
Chris@0 42 * - title_display: Title display setting.
Chris@0 43 *
Chris@0 44 * @see template_preprocess_form_element()
Chris@0 45 *
Chris@0 46 * @ingroup themeable
Chris@0 47 */
Chris@0 48 #}
Chris@0 49 {%
Chris@0 50 set classes = [
Chris@0 51 'js-form-item',
Chris@0 52 'form-item',
Chris@0 53 'js-form-type-' ~ type|clean_class,
Chris@0 54 'form-item-' ~ name|clean_class,
Chris@0 55 'js-form-item-' ~ name|clean_class,
Chris@0 56 title_display not in ['after', 'before'] ? 'form-no-label',
Chris@0 57 disabled == 'disabled' ? 'form-disabled',
Chris@0 58 errors ? 'form-item--error',
Chris@0 59 ]
Chris@0 60 %}
Chris@0 61 {%
Chris@0 62 set description_classes = [
Chris@0 63 'description',
Chris@0 64 description_display == 'invisible' ? 'visually-hidden',
Chris@0 65 ]
Chris@0 66 %}
Chris@0 67 <div{{ attributes.addClass(classes) }}>
Chris@0 68 {% if label_display in ['before', 'invisible'] %}
Chris@0 69 {{ label }}
Chris@0 70 {% endif %}
Chris@0 71 {% if prefix is not empty %}
Chris@0 72 <span class="field-prefix">{{ prefix }}</span>
Chris@0 73 {% endif %}
Chris@0 74 {% if description_display == 'before' and description.content %}
Chris@0 75 <div{{ description.attributes }}>
Chris@0 76 {{ description.content }}
Chris@0 77 </div>
Chris@0 78 {% endif %}
Chris@0 79 {{ children }}
Chris@0 80 {% if suffix is not empty %}
Chris@0 81 <span class="field-suffix">{{ suffix }}</span>
Chris@0 82 {% endif %}
Chris@0 83 {% if label_display == 'after' %}
Chris@0 84 {{ label }}
Chris@0 85 {% endif %}
Chris@0 86 {% if errors %}
Chris@0 87 <div class="form-item--error-message">
Chris@0 88 {{ errors }}
Chris@0 89 </div>
Chris@0 90 {% endif %}
Chris@0 91 {% if description_display in ['after', 'invisible'] and description.content %}
Chris@0 92 <div{{ description.attributes.addClass(description_classes) }}>
Chris@0 93 {{ description.content }}
Chris@0 94 </div>
Chris@0 95 {% endif %}
Chris@0 96 </div>