input.twig

{% set input_attributes = create_attribute({
  type: 'text',
  name: form_state.value.name,
  id: id|default('test-sdc-text-field-' ~ random()),
  value: form_state.value.value,
}) %}

{% if form_state.value.required %}
  {% set input_attributes = input_attributes.setAttribute('required', true) %}
{% endif %}

<div{{ attributes }}>
  <label class="form-label" for="{{ input_attributes.id }}">
    {{ label }}
  </label>
  <input{{ input_attributes }}>
</div>

File

core/modules/system/tests/themes/sdc_theme_test/components/input/input.twig

View source
  1. {% set input_attributes = create_attribute({
  2. type: 'text',
  3. name: form_state.value.name,
  4. id: id|default('test-sdc-text-field-' ~ random()),
  5. value: form_state.value.value,
  6. }) %}
  7. {% if form_state.value.required %}
  8. {% set input_attributes = input_attributes.setAttribute('required', true) %}
  9. {% endif %}
  10. <div{{ attributes }}>
  11. <label class="form-label" for="{{ input_attributes.id }}">
  12. {{ label }}
  13. </label>
  14. <input{{ input_attributes }}>
  15. </div>

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.