form_builder() applies the following defaults to all form elements:
// Assign basic defaults common for all form elements.
$element += array(
'#required' => FALSE,
'#attributes' => array(),
'#title_display' => 'before',
);
The default for #attributes is a wonky serious and weird problem, when using trying to render themeable elements within the context of a form, like this:
$form['links']['#theme'] = 'links';
$form['links']['#links']['foo'] = array(...);
Due to form_builder()'s default for #attributes, theme_links() no longer applies the default theme variable value for 'attributes', as defined in drupal_common_theme() for theme_links().
Comments
Comment #1
sunRelated: #974502: Replace $element['#id'] with $element['#attributes']['id']
Comment #2
sunComment #4
sunI expected more, so if that's all...
Comment #6
sunRe-rolled against HEAD and fixed the test failures.
Comment #7
jacineWe actually ran into a similar issue with this (I think), when trying to use a different class for the wrapper of contextual links vs. the links inside of it. There seemed to be no way to use a different class for the wrapper without hardcoding it with #prefix and #suffix, which sucks. So... you can set both #theme_wrappers and #theme, but in the situation where they both share the #attributes argument (or any other maybe any argument I guess), you run into a problem where those will end up being shared, regardless. Maybe that is a separate issue or I was doing something wrong though?
I guess what I am asking is... Is this problem specific to form_builder() and how does this really solve anything?
Is this something that will have to be done everywhere? Because that would be a tad annoying.
Comment #8
sunYes, the problem is specific to form_builder(), because of the #attributes default value being applied here:
Most affected functions are only element-specific Form API #process functions; i.e., not in the theme layer.
As kinda visible through this patch, only in theme functions that take a render element in the first place and that actively try to process or do something special with the passed in #attributes, which is not very usual.
And of course, this change kinda highlights how intertwined theme functions can be. The fact that theme_tableselect() relied on #attributes being set means that it wasn't really used outside of a form.
Comment #9
sunRe-rolled against HEAD.
Comment #10
sun#9: drupal8.form-attributes-default.9.patch queued for re-testing.
Comment #13
mgiffordThis still a concern in D8? Unassigned issue too.
Comment #29
quietone commented8 years it was asked if this is still relevant. There hasn't been a reply which suggests this is outdated. So, one last check on that.
Is this still relevant for Drupal 10+?
Since we need more information to move forward with this issue, I am setting the status to Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Comment #30
quietone commentedIt has been 5 months and there has been no confirmation that this is still a problem. Therefore closing.