protected function BrowserController::getBlocks in Layout Builder Browser 8
Gets a render array of block links.
Parameters
\Drupal\layout_builder\SectionStorageInterface $section_storage: The section storage.
int $delta: The delta of the section to splice.
string $region: The region the block is going in.
array $blocks: The information for each block.
Return value
array The block links render array.
1 call to BrowserController::getBlocks()
- BrowserController::browse in src/
Controller/ BrowserController.php - Overrides the core ChooseBlockController::build.
File
- src/
Controller/ BrowserController.php, line 228
Class
- BrowserController
- Class BrowserController.
Namespace
Drupal\layout_builder_browser\ControllerCode
protected function getBlocks(SectionStorageInterface $section_storage, $delta, $region, array $blocks) {
$links = [];
foreach ($blocks as $block_id => $block) {
$attributes = $this
->getAjaxAttributes();
$attributes['class'][] = 'js-layout-builder-block-link';
$attributes['class'][] = 'layout-builder-browser-block-item';
$block_render_array = [];
if (!empty($block["layout_builder_browser_data"]) && isset($block["layout_builder_browser_data"]->image_path) && trim($block["layout_builder_browser_data"]->image_path) != '') {
$block_render_array['image'] = [
'#theme' => 'image',
'#uri' => $block["layout_builder_browser_data"]->image_path,
'#alt' => $block['layout_builder_browser_data']->image_alt,
];
}
$block_render_array['label'] = [
'#markup' => empty($block["layout_builder_browser_data"]) ? $block['admin_label'] : $block["layout_builder_browser_data"]
->label(),
];
$link = [
'#type' => 'link',
'#title' => $block_render_array,
'#url' => Url::fromRoute('layout_builder.add_block', [
'section_storage_type' => $section_storage
->getStorageType(),
'section_storage' => $section_storage
->getStorageId(),
'delta' => $delta,
'region' => $region,
'plugin_id' => $block_id,
]),
'#attributes' => $attributes,
];
$links[] = $link;
}
return $links;
}