Skip to content

Instantly share code, notes, and snippets.

@zachharkey
Created May 9, 2012 00:58
Show Gist options
  • Save zachharkey/2640840 to your computer and use it in GitHub Desktop.
Save zachharkey/2640840 to your computer and use it in GitHub Desktop.
Add block_class classes to panel pane markup
<?php
/**
* Modify panels pane template variables
*/
function MYTHEME_preprocess_panels_pane(&$variables) {
// Merge block_class classes into the pane's $classes_array
if (module_exists('block_class')) {
// Insert additional classes into panels panes.
if ($variables['pane']->type == 'block') {
// Infer the block's $module and $delta from the pane subtype.
$block_parts = explode('-', $variables['pane']->subtype);
// Load the block based on the block parts.
$block = block_load($block_parts[0], $block_parts[1]);
// Return block_class classes as string.
$css_class = block_class($block);
// Add a generic module type block class.
$variables['classes_array'][] = drupal_html_class('pane-' . $block->module);
// Add $css_class to the $classes_array.
$variables['classes_array'][] = $css_class;
}
}
}
@acontia
Copy link

acontia commented Jul 11, 2014

I found that this fails if the delta of the module contains a "-", like in blocks generated by Views.
I fixed it replacing line 13 with the following:

  $module = array_shift($block_parts);
  $delta = implode('-', $block_parts);
  $block = block_load($module, $delta);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment