Last active
August 29, 2015 14:14
-
-
Save sachbearbeiter/9760ef62e43461cf4894 to your computer and use it in GitHub Desktop.
D8: Theming examples: Theme: Additional suggestion for content block templates: taking the bundle type into account. *First results of struggling through Drupal 8 - better solutions are probably out there! **Drupal 8 is still Beta - improvements through API modifications are possible!
This file contains 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_theme_suggestions_HOOK_alter(). | |
*/ | |
function MYTHEME_theme_suggestions_block_alter(array &$suggestions, array $variables) | |
{ | |
$block = $variables['elements']; | |
$blockType = $block['#configuration']['provider']; | |
if ($blockType == "block_content") { | |
$bundle = $block['content']['#block_content']->bundle(); | |
$blockUuid = $block['content']['#block_content']->uuid(); | |
$blockId = $block['#id']; | |
$suggestions[] = 'block__' . $blockType . '__' . $bundle; | |
$suggestions[] = 'block__' . $blockType . '__' . $bundle . '__' . $blockId; | |
$suggestions[] = 'block__' . $blockType . '__' . $bundle . '__' . $blockUuid; | |
} | |
} |
This file contains 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
As Example | |
admin/structure/block/block-content/types | |
As custom block type is defined: "header_content_block": | |
<!-- FILE NAME SUGGESTIONS: | |
new! block--block-content--header-content-block--7bd0dc95-f2ee-4e70-8a5a-90d718384712.html.twig | |
new! block--block-content--header-content-block--registernowheaderblock.html.twig | |
new! block--block-content--header-content-block.html.twig | |
* block--registernowheaderblock.html.twig | |
* block--block-content--7bd0dc95-f2ee-4e70-8a5a-90d718384712.html.twig | |
* block--block-content.html.twig | |
* block.html.twig | |
--> | |
The hierachy ist not perfect - no idea, how to fix ... better would be: | |
<!-- FILE NAME SUGGESTIONS: | |
* block--registernowheaderblock.html.twig | |
* block--block-content--7bd0dc95-f2ee-4e70-8a5a-90d718384712.html.twig | |
new! block--block-content--header-content-block.html.twig | |
* block--block-content.html.twig | |
* block.html.twig | |
--> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment