Disclaimer

To report a problem in this issue

  1. Make sure you have tested this module with the referenced version in this issue (currently 7.x-2.x-dev).
  2. 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.
  3. Specify the Drupal Core version.
  4. 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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

berenddeboer’s picture

Status: Needs review » Needs work

Please submit patch as attached file. I couldn't use this.

sketman’s picture

Was this patch commited please? I tryed it but it does not work for me in Panels panes. This would be an excellent feature.

patrickroma’s picture

Is there also a back port of this for D6?

Zach Harkey’s picture

Status: Needs work » Needs review
FileSize
985 bytes

Here'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.

Zach Harkey’s picture

FileSize
985 bytes

Here is a slightly better version with the additional generic "module type" class to be prefixed with 'pane-' instead of 'block-' which makes more sense.

Zach Harkey’s picture

FileSize
985 bytes

Sorry, I attached the wrong file, use this one:

berenddeboer’s picture

Status: Needs review » Closed (fixed)

Committed.

malcomio’s picture

Version: 7.x-1.0 » 7.x-2.x-dev
Status: Closed (fixed) » Needs review
FileSize
555 bytes

As 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.

Vj’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Patch #8 works for webform as well as for views block also.

marcoka’s picture

i tested the latest dev version with panels 3. i can not see my class beeing added to the block.

  • berenddeboer committed f581ec7 on 8.x-1.x
    Issue #1386774 by Zach Harkey: Support for panel panes.
    
DYdave’s picture

Title: Blocks in panel panes » Panels and related modules: Compatibility issues
Issue summary: View changes
Status: Reviewed & tested by the community » Needs review
Related issues: +#2331523: Views Blocks in Panel panes (rendered as system blocks)

Hi 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!