function _bricks_build_layout_from_items in Bricks 8
Same name and namespace in other branches
- 2.x bricks.module \_bricks_build_layout_from_items()
Helper function for layout handling in _bricks_nest_items().
1 call to _bricks_build_layout_from_items()
- _bricks_nest_items in ./
bricks.module - Helper function: converts element's items to a tree structure.
File
- ./
bricks.module, line 89
Code
function _bricks_build_layout_from_items($layout, $items) {
$layoutPluginManager = \Drupal::service('plugin.manager.core.layout');
if (!$layoutPluginManager
->hasDefinition($layout)) {
drupal_set_message(t('Layout `%layout_id` is unknown.', [
'%layout_id' => $layout,
]), 'warning');
return;
}
// Provide any configuration to the layout plugin if necessary.
$layoutInstance = $layoutPluginManager
->createInstance($layout);
$regionNames = $layoutInstance
->getPluginDefinition()
->getRegionNames();
// Adjust the lengths:
$count = min(count($regionNames), count($items));
$regionNames = array_slice($regionNames, 0, $count);
$items = array_slice($items, 0, $count);
// Build the content for your regions.
$regions = array_combine($regionNames, $items);
// This builds the render array.
return $layoutInstance
->build($regions);
}