I would like add the class 'panel-primary' to some (not all) panels. I tried to use hook_preprocess_fieldset to add this class but this hook seems not to work with the bootstrap theme. Is there a better or correct way of doing this?

Comments

mike82 created an issue. See original summary.

markhalliwell’s picture

Status: Active » Closed (works as designed)

...some (not all) panels.

This sounds like there could be some logic that may be preventing the class from being added...

However, I think this has more to do with https://drupal-bootstrap.org/api/bootstrap/templates%21bootstrap%21boots...

I'd recommend stepping through and seeing that hook and class are actually being invoked (I think they are).

I think the real issue is because the panel type is being added after (in the template), it takes precedence visually (last class wins).

Try setting '#panel_type' => 'primary' for the fieldset in question.

Then you won't need a preprocess hook at all.

mike82’s picture

Try setting '#panel_type' => 'primary' for the fieldset in question.

How can I set this if hook_preprocess_fieldset is not called?

For example the commerce checkout pane:

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'fieldset' -->
<!-- FILE NAME SUGGESTIONS:
   x bootstrap-panel.html.twig
   * fieldset.html.twig
-->
<!-- BEGIN OUTPUT from 'themes/contrib/bootstrap/templates/bootstrap/bootstrap-panel.html.twig' -->
<div class="checkout-pane checkout-pane-payment-information form-item js-form-item form-wrapper js-form-wrapper panel panel-default" data-drupal-selector="edit-payment-information" id="edit-payment-information">

hook_preprocess_fieldset doesn't work for this fieldset. How can I change the style to panel-primary or set #panel_type' => 'primary' ?

markhalliwell’s picture

Use hook_preprocess_bootstrap_panel() or, preferably, hook_form_FORM_ID_alter() and add it to the form element before it makes its way through the theme system.

mike82’s picture

Thanks, hook_form_FORM_ID_alter() works, I was only focussing on preprocess hooks.
But hook_preprocess_bootstrap_panel() is not called, neither is hook_preprocess_fieldset(). I think it's strange that both preprocess hooks do not work. I can exclude that this is some caching issue, as hook_preprocess_fieldset() works fine for other fieldsets. Is it a bug or is there a reason?