Problem/Motivation
Stable9's form-element template doesn't add the form-type-* class which is used by many contrib modules in CSS and JS selectors.
This is how the classes variable is set in the starterkit_theme/form-element.html.twig
{%
set classes = [
'js-form-item',
'form-item',
'js-form-type-' ~ type|clean_class,
'form-type-' ~ type|clean_class, <--- FORM TYPE IS ADDED HERE.
'js-form-item-' ~ name|clean_class,
'form-item-' ~ name|clean_class,
title_display not in ['after', 'before'] ? 'form-no-label',
disabled == 'disabled' ? 'form-disabled',
errors ? 'form-item--error',
]
%}
This is how the classes variable is set in the stable9/form-element.html.twig
{%
set classes = [
'js-form-item',
'form-item',
'js-form-type-' ~ type|clean_class,
'form-item-' ~ name|clean_class,
'js-form-item-' ~ name|clean_class,
title_display not in ['after', 'before'] ? 'form-no-label',
disabled == 'disabled' ? 'form-disabled',
errors ? 'form-item--error',
]
%}
Steps to reproduce
Build a form and inspect its elements. No elements have the form-type- class related to its type.
Proposed resolution
Add the 'form-type-' ~ type|clean_class, snippet to the classes variable:
{%
set classes = [
'js-form-item',
'form-item',
'form-type-' ~ type|clean_class,
'js-form-type-' ~ type|clean_class,
'form-item-' ~ name|clean_class,
'js-form-item-' ~ name|clean_class,
title_display not in ['after', 'before'] ? 'form-no-label',
disabled == 'disabled' ? 'form-disabled',
errors ? 'form-item--error',
]
%}
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3380021-2.patch | 529 bytes | dineshkumarbollu |
Issue fork drupal-3380021
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3380021-stable9-form-element-template
changes, plain diff MR !4842
Comments
Comment #2
dineshkumarbollu commentedprovided patch, added
'form-type-' ~ type|clean_classin stable9 theme.please review.Comment #3
andre.bonon@dineshkumarbollu it works. Thanks for providing a patch for that.
Comment #4
lauriiiThe contributed modules should be using
js-form-type-{type}class. Looks like there are quite a few uses of this class in contrib so maybe the pragmatic solution would be to just add the class to Stable. Tagging with FEFM review tag to get their feedback.Comment #5
ckrinaAgreed, this addition makes sense for me.
Comment #6
bnjmnmI was trying to put myself in the shoes of a stark-theme-diehard who wants no excess markup, but this is a convention intended for functionality, not presentation, and I'd hope that theoretical purist would be OK with the markup being a little busier in order for contrib. modules to work as expected. This is a nice addition for the next minor.
Comment #7
lauriiiLooks like this would be ready to go then! Should we open a CR for this?
Comment #10
lauriiiCommitted 724c8d4 and pushed to 11.x. Thanks!
Added a brief snippet to the 10.2.0 draft release notes.