You are here

public function ErlLayout::build in Entity Reference with Layout 8

Build a render array for layout with regions.

Parameters

array $regions: An associative array keyed by region name, containing render arrays representing the content that should be placed in each region.

Return value

array Render array for the layout with regions.

Overrides LayoutDefault::build

File

modules/erl_layouts/src/Plugin/Layout/ErlLayout.php, line 34

Class

ErlLayout
Layout class with various formatting options for custom ERL layouts.

Namespace

Drupal\erl_layouts\Plugin\Layout

Code

public function build(array $regions) {
  $configuration = $this
    ->getConfiguration();
  $build = parent::build($regions);
  if (!empty($configuration['layout_classes'])) {
    $layout_classes = is_array($configuration['layout_classes']) ? implode(' ', $configuration['layout_classes']) : $configuration['layout_classes'];
    $build['#attributes']['class'][] = $layout_classes;
  }
  if (!empty($configuration['layout_bg_color'])) {
    $build['#attributes']['style'] = 'background-color: ' . $configuration['layout_bg_color'];
  }
  foreach ($this
    ->getPluginDefinition()
    ->getRegionNames() as $region_name) {
    if (array_key_exists($region_name, $regions)) {
      if ($configuration[$region_name]['classes']) {
        $region_classes = is_array($configuration[$region_name]['classes']) ? implode(' ', $configuration[$region_name]['classes']) : $configuration[$region_name]['classes'];
        $build[$region_name]['#attributes']['class'][] = $region_classes;
      }
      if ($configuration[$region_name]['bg_color']) {
        $build[$region_name]['#attributes']['style'] = 'background-color: ' . $configuration[$region_name]['bg_color'];
      }
    }
  }
  return $build;
}