Gin theme checkbox styles breaks Webform custom composite fields required

Created on 20 April 2022, over 2 years ago
Updated 10 January 2024, 10 months ago

Problem/Motivation

For custom composite fields in a Webform, it isn’t possible to toggle the "required" boolean checkbox.

Theme suggestions are not getting applied:

Checkbox for required field used elsewhere where the toggle is provided.

<!-- FILE NAME SUGGESTIONS:
   * input--checkbox.html.twig
   x input--checkbox--toggle.html.twig
   * input--checkbox.html.twig
   * input.html.twig
-->

Checkbox for required field inside composite field:

  <!-- THEME DEBUG -->
  <!-- THEME HOOK: 'input__checkbox' -->
  <!-- FILE NAME SUGGESTIONS:
    x input--checkbox.html.twig
    x input--checkbox.html.twig
    * input.html.twig
  -->

Steps to reproduce

Drupal 9 w/ drupal/webform:^6 and drupal/gin:^3@beta
Create a webform with a "Custom Composite" element, add at least one field inside the composite layout.
See that the "required" checkbox is invisible, and there is no styled toggle element.

Proposed resolution

Fix the template suggestions that add input__checkbox__toggle for the webform composite required checkbox.

WebformElementComposite.php explicitly adds #error_no_message = TRUE to this field, which is why it is not getting the checkbox style applied.

I see two possible approaches:

  1. Modify webform in some way to flag the field as a "one off" checkbox, instead of depending on #error_no_message
  2. Alter the template suggestion logic in Gin theme to look for a string in the field id or name that contains the word "required"?
  3. Any better ideas???

Remaining tasks

Determine approach.
Write patch.

User interface changes

Gin theme no longer breaks Webform custom composite required fields checkbox.

API changes

N/a

Data model changes

N/a

🐛 Bug report
Status

Closed: cannot reproduce

Version

3.0

Component

Code

Created by

🇪🇨Ecuador jwilson3

Live updates comments and jobs are added and updated live.
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.

  • 🇫🇷France goz

    I have a similar issue, except I still don't understand why.
    I don't use webform, it's a boolean field in a node, displayed by boolean_checkbox form widget, with display_label option to 1.

    In my case, i can see debugging gin_theme_suggestions_input_alter() function that #error_no_message exists and is TRUE.

    Reading #2643012: Add property to identify if checkbox/radio is in group of checkboxes/radios , checkboxes group is can be tested thanks to #error_no_message key AND #weight. After few tests and reading \Drupal\Core\Render\Element\Checkboxes, it seems checking #weight is float is more relevant than #error_no_message... but not the solution either.

    Here is an example of a form. I should have toggle checkbox for fields, but none is displayed :

    • Publié (published status)
    • My checkbox (a boolean field)
    • Sidebar > Create new revision
    • Sidebar > Menu settings > Provide a menu link
    • Sidebar > Simple XML Sitemap > Regenerate all sitemaps after hitting Save
    • Sidebar > URL alias > Generate automatic URL alias

    Then checking #weight is not float to use template suggestion :

    function gin_theme_suggestions_input_alter(array &$suggestions, array $variables) {
      if ($variables['element']['#type'] === 'checkbox') {
        // Way to identify if checkbox is in a checkboxes group
        // as Drupal doesn't provide one yet (see #2643012)
        if (!is_float($variables['element']['#weight'])) {
          $suggestions[] = 'input__checkbox__toggle';
        }
      }
    }
    

    Finally, removing condition to always use template suggestion :

    function gin_theme_suggestions_input_alter(array &$suggestions, array $variables) {
      if ($variables['element']['#type'] === 'checkbox') {
        // Way to identify if checkbox is in a checkboxes group
        // as Drupal doesn't provide one yet (see #2643012)
    //    if (!is_float($variables['element']['#weight'])) {
          $suggestions[] = 'input__checkbox__toggle';
    //    }
      }
    }
    

  • Status changed to Closed: cannot reproduce 10 months ago
  • 🇨🇭Switzerland saschaeggi Zurich

    Closing as I can't reproduce these issues on the latest Drupal versions.

Production build 0.71.5 2024