You are here

public function GridStackLayout::build in GridStack 8.2

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

src/Plugin/Layout/GridStackLayout.php, line 17

Class

GridStackLayout
Provides a GridStack class for Layout plugins.

Namespace

Drupal\gridstack\Plugin\Layout

Code

public function build(array $regions) {
  ksort($regions);
  $settings = $this
    ->getConfiguration();
  $definition = $this
    ->getPluginDefinition();
  $name = $definition
    ->get('optionset');
  $optionset = GridStack::loadWithFallback($name);
  $variant = $this->manager
    ->getEngine($settings, 'variant')
    ->override($optionset, $settings);

  // Provides settings.
  $settings['optionset'] = $name;
  $settings['_stylizer'] = TRUE;
  $settings = array_filter($settings);
  $build = [
    'items' => $this
      ->interpolateItems($optionset, $settings, $regions),
    'optionset' => $optionset,
    'settings' => $settings,
    'layout' => $definition,
    'variant' => $variant,
  ];

  // Still a check in case it is removed by another alter.
  if ($library = $this->pluginDefinition
    ->getLibrary()) {
    $build['attached']['library'][] = $library;
  }

  // Must pass the layout blueprint to Layout Builder regardless empty.
  return $this->manager
    ->build($build);
}