"required" flag not available in form-element.html.twig

Created on 5 December 2017, about 7 years ago
Updated 25 August 2023, over 1 year ago

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

  1. Find a form with a required field
  2. Print the required variable for form fields within the theme template file
  3. Variable will be empty for required fields
  4. 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.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
FormΒ  β†’

Last updated 1 day ago

Created by

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    @Kristen Pol you are correct. Actually surprised it didn't get moved back automatically after 2 weeks by the bot.

    The patch in #39 will have to be updated for D10 as some themes have been removed.

    Since we are updating all the templates think we will need a change record since from what I can tell required can be NULL. If a contrib theme is doing a certain check could this cause errors or warnings?

  • Status changed to Needs review over 1 year ago
  • last update over 1 year ago
    30,058 pass
  • πŸ‡©πŸ‡ͺGermany hchonov πŸ‡ͺπŸ‡ΊπŸ‡©πŸ‡ͺπŸ‡§πŸ‡¬

    Re-roll for 10.1.x

  • last update over 1 year ago
    29,469 pass
  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thanks! Still think this will need a change record.

Production build 0.71.5 2024