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.
Disclaimer
To report a problem in this issue
- Make sure you have tested this module with the referenced version in this issue (currently 7.x-2.x-dev).
- Specify the exact versions of the modules you are using for: ctools, panels and any other Panels related modules, such as Panelizer and Fieldable panels panes.
- Specify the Drupal Core version.
- Screenshots are optional, but greatly appreciated.
For example:
- block_class-7.x-2.3+3-dev
- panels-7.x-3.5+21-dev
- ctools-7.x-1.9+4-dev
- drupal-7.43
The panel module allows us to display our blocks in custom panes. Unfortunately, this module uses only the hook_preprocess_block and not the hook_preprocess_panels_pane to add the custom class. This little patch allows us to inherit css classes from the block system to the panel module.
Index: block_class.module
===================================================================
--- block_class.module (Revision 113)
+++ block_class.module (Arbeitskopie)
@@ -9,6 +9,19 @@
$vars['classes_array'] = array_merge($vars['classes_array'], explode(' ', $classes));
}
+/*
+ * Extend panel block's classes with any user defined classes.
+ * Implements hook_preprocess_hook()
+ */
+function block_class_preprocess_panels_pane(&$vars) {
+ if ($vars['pane']->type != 'block') return;
+ if (!preg_match('~^block-(\d+)$~', $vars['pane']->subtype, $m)) return;
+ $block = new stdClass();
+ $block->module = 'block';
+ $block->delta = $m[1];
+ $classes = block_class($block);
+ $vars['classes_array'] = array_merge($vars['classes_array'], explode(' ', $classes));
+}
/**
* Return classes as string
This solution is not the best, because the block is already rendered in the $vars['content'] array. An earlier approach should be preffered.
Greetings
Comment | File | Size | Author |
---|---|---|---|
#8 | blocks_panels-1386774-8.patch | 555 bytes | malcomio |
#6 | block_class-1386774.patch | 985 bytes | Zach Harkey |
#5 | block_class-1386774.patch | 985 bytes | Zach Harkey |
#4 | block_class-1386774.patch | 985 bytes | Zach Harkey |
Comments
Comment #1
berenddeboer CreditAttribution: berenddeboer commentedPlease submit patch as attached file. I couldn't use this.
Comment #2
sketman CreditAttribution: sketman commentedWas this patch commited please? I tryed it but it does not work for me in Panels panes. This would be an excellent feature.
Comment #3
patrickroma CreditAttribution: patrickroma commentedIs there also a back port of this for D6?
Comment #4
Zach Harkey CreditAttribution: Zach Harkey commentedHere's the code I've been using to solve this issue. Rolled into a patch.
You can also add this functionality at the theme level by adding this snippet to your template.php.
Comment #5
Zach Harkey CreditAttribution: Zach Harkey commentedHere is a slightly better version with the additional generic "module type" class to be prefixed with 'pane-' instead of 'block-' which makes more sense.
Comment #6
Zach Harkey CreditAttribution: Zach Harkey commentedSorry, I attached the wrong file, use this one:
Comment #7
berenddeboer CreditAttribution: berenddeboer commentedCommitted.
Comment #8
malcomio CreditAttribution: malcomio commentedAs it stands, only blocks created by the block module will be affected by this.
For example webforms as blocks don't have the class when added to panels.
This patch works for me on a limited test so far.
Comment #9
Vj CreditAttribution: Vj commentedPatch #8 works for webform as well as for views block also.
Comment #10
marcoka CreditAttribution: marcoka commentedi tested the latest dev version with panels 3. i can not see my class beeing added to the block.
Comment #12
DYdave CreditAttribution: DYdave commentedHi guys!
Thanks a LOT for following-up on this issue and I sincerely apologize for the delay of this reply.
I would like to say something very important for this ticket (see issue summary):
If we would like to get closer to fixing this issue, we're going to have to be VERY specific with the VERSIONS of the modules related with this problem.
As the ticket references it, please ALWAYS test this issue with the referenced version, which is currently: 7.x-2.x-dev.
Also, please be VERY explicit on whether you are using any Panels related modules such as: Panelizer and Fieldable panels panes
Where are we standing with this?
Back to Needs review to trigger tests.
Would anybody care helping on a Test Case for Block Class integrated with Panels? :D
As long as we don't have any SimpleTests to support this patch or any Panels related patch, I wouldn't feel comfortable having anything in this ticket or the related ones committed.
Currently, it seems there are still so many moving parts on the Panels/Ctools side....
So I guess we will probably have to wait for a bit and see what happens there (at least until their next stable release).
I've been having compatibility issues with panels AND ctools in many block, Views or formatter related modules I've been maintaining.... so I've seen quite a lot of changes going on there.
Please let us know if you would have any further comments, feedback, questions, issues, objections, suggestions or concerns on this issue, any help would be greatly appreciated.
Many thanks in advance to everyone for your reviews, testing, reporting and participation in this module's issue tracker.
Cheers!