You are here

public function PatternLayout::build in UI Patterns 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/ui_patterns_layouts/src/Plugin/Layout/PatternLayout.php, line 83

Class

PatternLayout
Class LayoutDefault.

Namespace

Drupal\ui_patterns_layouts\Plugin\Layout

Code

public function build(array $regions) {
  $configuration = $this
    ->getConfiguration();

  // Remove default field template if "Only content" option has been selected.
  if ($configuration['pattern']['field_templates'] == 'only_content') {
    $this
      ->processOnlyContentFields($regions);
  }

  // Patterns expect regions to be passed along in a render array fashion.
  $fields = [];
  foreach ($regions as $region_name => $region) {
    $fields[$region_name] = $regions[$region_name];
  }
  return [
    '#type' => 'pattern',
    '#id' => $this
      ->getPluginDefinition()
      ->get('additional')['pattern'],
    '#fields' => $fields,
    '#variant' => $configuration['pattern']['variant'],
  ] + $this->elementInfo
    ->getInfo('pattern');
}