Last active
June 12, 2017 06:10
-
-
Save davebeach/2f29f64d48f8a502a07697ef8b491149 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* @author | |
* https://drupal.stackexchange.com/questions/192616/how-to-make-a-theme-hook-suggestion-for-blocks-according-to-region/192623#192623 | |
*/ | |
use Drupal\block\Entity\Block; | |
function MODULE_theme_suggestions_block_alter(array &$suggestions, array $variables) { | |
if (!empty($variables['elements']['#id'])) { | |
$block = Block::load($variables['elements']['#id']); | |
$suggestions[] = 'block__' . $block->getRegion() . '__' . $variables['elements']['#id']; | |
} | |
/* Use this 'else if' only if you are using page_manager module and want to know which region is the block */ | |
else if (isset($variables['elements']['#configuration']['region'])) { | |
$suggestions[] = 'block__page_' . $variables['elements']['#configuration']['region'] . '__' . end(explode(':', $variables['elements']['#plugin_id'])); | |
} | |
return $suggestions; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment