You are here

public function Render::renderRegion in Bamboo Twig 8.4

Same name and namespace in other branches
  1. 8.5 bamboo_twig_loader/src/TwigExtension/Render.php \Drupal\bamboo_twig_loader\TwigExtension\Render::renderRegion()
  2. 8.2 bamboo_twig_loader/src/TwigExtension/Render.php \Drupal\bamboo_twig_loader\TwigExtension\Render::renderRegion()
  3. 8.3 bamboo_twig_loader/src/TwigExtension/Render.php \Drupal\bamboo_twig_loader\TwigExtension\Render::renderRegion()

Builds the render array of a given region.

Parameters

string $region: The region to build.

string $theme: (optional) The name of the theme to load the region. If it is not provided then default theme will be used.

Return value

array A render array to display the region content.

File

bamboo_twig_loader/src/TwigExtension/Render.php, line 214

Class

Render
Provides some renderer as Twig Extensions.

Namespace

Drupal\bamboo_twig_loader\TwigExtension

Code

public function renderRegion($region, $theme = NULL) {
  $blocks = $this
    ->getBlockStorage()
    ->loadByProperties([
    'region' => $region,
    'theme' => $theme ?: $this
      ->getConfigFactory()
      ->get('system.theme')
      ->get('default'),
  ]);
  $view_builder = $this
    ->getEntityTypeManager()
    ->getViewBuilder('block');
  $build = [];

  /* @var $blocks \Drupal\block\BlockInterface[] */
  foreach ($blocks as $id => $block) {
    $block_plugin = $block
      ->getPlugin();
    if ($block_plugin instanceof TitleBlockPluginInterface) {
      $request = $this->requestStack
        ->getCurrentRequest();
      if ($route = $request->attributes
        ->get(RouteObjectInterface::ROUTE_OBJECT)) {
        $block_plugin
          ->setTitle($this->titleResolver
          ->getTitle($request, $route));
      }
    }
    $build[$id] = $view_builder
      ->view($block);
  }
  return $build;
}