Created
January 29, 2014 20:49
-
-
Save ezheidtmann/8696753 to your computer and use it in GitHub Desktop.
Add region-based suggestions for bean blocks (Drupal 7, bean module)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_preprocess_block() | |
* | |
* For each bean block, add a template suggestion containing the name of the | |
* region where the block will appear. | |
* | |
* Requires "bean" module (fieldable blocks) | |
*/ | |
function THEME_preprocess_entity(&$vars, $hook) { | |
if ($vars['entity_type'] == 'bean') { | |
if (isset($vars['elements']['#block'])) { | |
$region = $vars['elements']['#block']->region; | |
if ($region) { | |
$new_suggestions = array(); | |
// Regions are usually lowercase and don't contain dashes, but it can't | |
// hurt to be sure. | |
$lc_region = str_replace('-', '_', strtolower($region)); | |
$new_suggestions[] = $hook . '__region_' . $lc_region; | |
foreach ($vars['theme_hook_suggestions'] as $suggestion) { | |
$new_suggestions[] = $suggestion; | |
$new_suggestions[] = $suggestion . '__region_' . $lc_region; | |
} | |
$vars['theme_hook_suggestions'] = $new_suggestions; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment