Problem/Motivation
The documented required
variable is missing from the form-element.html.twig
template variables.
The problem applies to any form with required fields (e.g. core forms, webform). The variable does not exist for non-required fields or required fields, so there is no indicator if the wrapped element is required or not.
Example: The classy template file is /core/themes/classy/templates/form/form-element.html.twig
and the documentation for that shows the required
variable:
required: The required marker, or empty if the associated form element is not required.
Steps to reproduce
- Find a form with a required field
- Print the
required
variable for form fields within the theme template file - Variable will be empty for required fields
- Expected: Variable will be set for required fields
Proposed resolution
Debug why the required
variable is not set and fix the problem.
Remaining tasks
- Debug
- Create patch
- Review patch
- Test patch
- Commit :)
User interface changes
API changes
Data model changes
Release notes snippet
Original report by @thomas.frobieter
Context:
https://api.drupal.org/api/drupal/core%21themes%21classy%21templates%21f...
says:
- "required: The required marker, or empty if the associated form element is"
Problem:
The documented "required" key / value is completely missing in the template variables of "form-element.html.twig". The problem applies to all kind of forms with required fields, core forms, webform, ...
It's neither existing für non-required fields nor for required fields. So there's no indicator at this point if the wrapped element is required or not.
The used template file is "/core/themes/classy/templates/form/form-element.html.twig".
Proposed solution:
Check why "required" flag variable is not set and correct it to be always set true / false.