You are here

public function DisplayBase::mapBlocksToLayout in Layout 8.2

Implements DisplayInterface::mapBlocksToLayout().

@todo Decouple this implementation from this class, so that it could be more easily customized.

Overrides DisplayInterface::mapBlocksToLayout

3 calls to DisplayBase::mapBlocksToLayout()
Display::remapToLayout in lib/Drupal/layout/Entity/Display.php
Implements BoundDisplayInterface::remapToLayout().
Display::sortBlocks in lib/Drupal/layout/Entity/Display.php
Transform the stored blockConfig into a sorted, region-oriented array.
UnboundDisplay::generateDisplay in lib/Drupal/layout/Entity/UnboundDisplay.php
Implements UnboundDisplayInterface::generateDisplay().

File

lib/Drupal/layout/Config/DisplayBase.php, line 94
Definition of Drupal\layout\Config\DisplayBase.

Class

DisplayBase
Base class for 'display' and 'unbound_display' configuration entities.

Namespace

Drupal\layout\Config

Code

public function mapBlocksToLayout(LayoutInterface $layout) {
  $types = array();
  $layout_regions = $layout
    ->getRegions();
  $layout_regions_indexed = array_keys($layout_regions);
  foreach ($layout_regions as $name => $info) {
    $types[$info['type']][] = $name;
  }
  $remapped_config = array();
  foreach ($this->blockInfo as $name => $info) {

    // First, if there's a direct region name match, use that.
    if (!empty($info['region']) && isset($layout_regions[$info['region']])) {

      // No need to do anything.
    }
    else {
      if (!empty($types[$info['region-type']])) {
        $info['region'] = reset($types[$info['region-type']]);
      }
      else {
        if (!isset($first_region)) {
          reset($layout_regions);
          $first_region = key($layout_regions);
        }
        $info['region'] = $first_region;
      }
    }
    $remapped_config[$name] = $info;
  }
  return $remapped_config;
}