The function bootstrap_preprocess_bootstrap_panel() is responsible for generating the variables used in the template bootstrap-panel.tpl.php.
Line 35 of bootstrap-panel.vars.php sets the ID attribute of the element that wraps the panel:
<?php
if (isset($element['#id'])) {
$attributes['id'] = $element['#id'];
$variables['target'] = '#' . $element['#id'] . ' > .collapse';
}
?>
However, this does not respect an ID that is set on the element elsewhere in the code.
For example, if I create a new Form API form fieldset, and set a custom ID on it:
<?php
$form['myfieldset'] = array(
'#type' => 'fieldset',
'#title' => t('My Fieldset'),
'#attributes' => array(
'id' => 'my-specific-fieldset-id',
),
);
?>
Normally, that ID 'my-specific-fieldset-id' would be set on the fieldset element in the final HTML. With the Bootstrap theme, however, it is overridden.
It should be: #my-specific-fieldset-id
Instead, it is: #edit-myfieldset
Comments
Comment #1
m.stentaAttached is a patch that fixes this issue. The approach I took was to check to see if $attributes['id'] is already set (it will be if $element['#attributes']['id'] is), and use that instead of $element['#id'] if it is. But it also uses $element['#id'] as a fallback if it's available (not sure if there's a specific reason that is being used). So it works in both cases.
Comment #2
asrobI tested it and it looks good to me, that's why I change its status to RTBC.
Comment #3
markhalliwellThis really should be using element_set_attributes() instead.
Comment #4
m.stenta@markcarver: Thanks for the input. I will try to put together a new patch soon.
Comment #5
m.stentaAttached is a new patch which reworks the bootstrap_preprocess_bootstrap_panel() function to use element_set_attributes().
I tried to follow the same approach taken in bootstrap_preprocess_button(). I added some comments to make the logic easier to follow, and tested to make sure that collapsible panels still work.
Comment #6
markhalliwellI wasn't really suggesting the variable be changed. That being said... if we're really going to refactor this, it should really be using _bootstrap_get_attributes():
Only need
idhere.This is a rather redundant comment and isn't needed.
I know this should be like this, but IIRC I had created this way specifically so the theme hook could be invoked directly (without an element being passed via FAPI). I could be mistaken and it may actually work with these changes if
_bootstrap_get_attributes()is implemented.Comment #7
m.stentaUpdated patch to use _bootstrap_get_attributes() per comment #6.1.
Removed all attributes except for id (per #6.2).
Reverted code in bootstrap_process_bootstrap_panel() (per #6.4)
I left the comment in that you mentioned in #6.3. I agree it's not really necessary, but felt that it was better to leave it for consistency with the structure of other comments and code. I like to err on the side of over-commenting, but it's not that important, so I can remove that too if you want.
Comment #8
m.stentaComment #10
markhalliwellTried cherry picking to 8.x-3.x, but that function has already undergone a significant amount of work, a new patch will need to be created from #7.
Comment #11
markhalliwellClosing this since 8.x is much more complicated and requires it's own focus.