public function BlockView::getBlock in Twig Extender 8.4
Same name and namespace in other branches
- 8 src/Plugin/TwigPlugin/BlockView.php \Drupal\twig_extender\Plugin\TwigPlugin\BlockView::getBlock()
- 8.2 src/Plugin/TwigPlugin/BlockView.php \Drupal\twig_extender\Plugin\TwigPlugin\BlockView::getBlock()
- 8.3 src/Plugin/TwigPlugin/BlockView.php \Drupal\twig_extender\Plugin\TwigPlugin\BlockView::getBlock()
- 4.x src/Plugin/TwigPlugin/BlockView.php \Drupal\twig_extender\Plugin\TwigPlugin\BlockView::getBlock()
Implementation for render block.
File
- src/
Plugin/ TwigPlugin/ BlockView.php, line 25
Class
- BlockView
- The plugin for check authenticated user.
Namespace
Drupal\twig_extender\Plugin\TwigPluginCode
public function getBlock($blockId) {
$block = Block::load($blockId);
if (!$block) {
return;
}
// Inject runtime contexts.
$block_plugin = $block
->getPlugin();
if ($block_plugin instanceof ContextAwarePluginInterface) {
$contexts = \Drupal::service('context.repository')
->getRuntimeContexts(array_values($block_plugin
->getContextMapping()));
\Drupal::service('context.handler')
->applyContextMapping($block_plugin, $contexts);
}
$blockContent = \Drupal::entityTypeManager()
->getViewBuilder('block')
->view($block);
return $blockContent;
}