public function DisplayBase::mapBlocksToLayout

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 drupal/core/modules/layout/lib/Drupal/layout/Plugin/Core/Entity/Display.php
Implements BoundDisplayInterface::remapToLayout().
Display::sortBlocks in drupal/core/modules/layout/lib/Drupal/layout/Plugin/Core/Entity/Display.php
Transform the stored blockConfig into a sorted, region-oriented array.
UnboundDisplay::generateDisplay in drupal/core/modules/layout/lib/Drupal/layout/Plugin/Core/Entity/UnboundDisplay.php
Implements UnboundDisplayInterface::generateDisplay().

File

drupal/core/modules/layout/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;
}