public function PageManager::loadInstances in Bootstrap Layouts 8.4
Same name and namespace in other branches
- 8.5 src/Plugin/BootstrapLayouts/PageManager.php \Drupal\bootstrap_layouts\Plugin\BootstrapLayouts\PageManager::loadInstances()
Loads layout instances.
Parameters
string[]|int[] $ids: Optional. An array of identifiers to load. If no identifiers are specified, then all available instances will be loaded.
Return value
\Drupal\bootstrap_layouts\BootstrapLayout[] An associative array of BootstrapLayout instances, keyed by identifier.
Overrides BootstrapLayoutsHandlerInterface::loadInstances
File
- src/
Plugin/ BootstrapLayouts/ PageManager.php, line 17
Class
- PageManager
- Handles Display Suite specific layout implementations.
Namespace
Drupal\bootstrap_layouts\Plugin\BootstrapLayoutsCode
public function loadInstances(array $entity_ids = NULL) {
$layouts = [];
$properties = [
'variant' => 'panels_variant',
];
if ($entity_ids) {
$properties['id'] = $entity_ids;
}
/** @var \Drupal\Core\Entity\EntityTypeManager $entity_type_manager */
$entity_type_manager = $this->container
->get('entity_type.manager');
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface[] $config_entities */
$config_entities = $entity_type_manager
->getStorage('page_variant')
->loadByProperties($properties);
foreach ($config_entities as $entity_id => $config_entity) {
if (($info = $config_entity
->get('variant_settings')) && isset($info['layout']) && isset($info['blocks'])) {
$id = $info['layout'];
// BootstrapLayout requires an associative array of "items" assigned to
// a particular region, keyed by that region. Unfortunately, Page
// Manager stores this value inside each block array; extract it.
$regions = [];
foreach ($info['blocks'] as $uuid => $block) {
$regions[$block['region']][$uuid] = $block;
}
// Retrieve any layout settings.
$settings = isset($info['layout_settings']) ? $info['layout_settings'] : [];
// Create a new BootstrapLayout instance.
$layouts[$entity_id] = new BootstrapLayout($id, $regions, $settings);
}
}
return $layouts;
}