Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I want to add class "row" to my "form-group" for an input field. Unfortunately with out overriding theme hooks, there's currently no way to get this done easily.
I added a little snippet into bootstrap_form_element() which will allow fields to add attributes to their parent wrappers.
It's a pretty small snippet, but adds a lot of extra flexibility for those who need it.
PS. Thx for #field_prefix and #field_suffix :) Helped me with another problem.
Comment | File | Size | Author |
---|---|---|---|
#3 | form_element_wrapper_attributes-bootstrap-2189117-3.patch | 3.65 KB | markhalliwell |
Comments
Comment #1
markhalliwellI do not see how this is useful, where else is
#parent_attributes
being used? This is definitely not a Drupal Best Practices™ method. What exactly is it you are attempting to accomplish here? Please provide code examples.Comment #2
j0rd CreditAttribution: j0rd commentedform elements in grid layout and adding classes to the parent form-group, which I needed for some JS widgets.
Drupal is not build really well to handle the flexibility of styling in theme frameworks like bootstrap. So you can nurf the theme for Drupal, or you can extend Drupal to handle more options of bootstrap.
Here's an example of the form I was able to create using this method. With out this method, a bunch of theme overwrites would have had to of been written.
Really the patch just allows for some added (and optional) flexibility.
As for where "#parent_attributes" is being used, it's just used to initialize the $attributes variable, which you then use in the parent group.
You can see that here
So really the patch just allows me to extend the parent div how ever I want in form API, instead of having to override it for each specific case (of which there are lots)
Example of my use in code:
Comment #3
markhalliwellAhh. Gotcha. The whole "parent" thing is what threw me, sorry for the misunderstanding. You are correct, however it should really be called
#wrapper_attributes
.Committed 3b7a855 to 7.x-3.x:
Comment #4
j0rd CreditAttribution: j0rd commented(y) thanks.
Comment #7
ryan.armstrong CreditAttribution: ryan.armstrong commentedMoving this to the 8.x-3.x branch as it has been committed to that branch. Making sure the fix gets tested in the Drupal 8 release.
Comment #8
ryan.armstrong CreditAttribution: ryan.armstrong commentedComment #11
markhalliwellI'm just moving this back to 7.x. If there needs to be any re-evaluation for 8.x, create a new issue.