function PlaceBlockPageVariant::build
Overrides BlockPageVariant::build
File
-
core/
modules/ block_place/ src/ Plugin/ DisplayVariant/ PlaceBlockPageVariant.php, line 91
Class
- PlaceBlockPageVariant
- Allows blocks to be placed directly within a region.
Namespace
Drupal\block_place\Plugin\DisplayVariantCode
public function build() {
$build = parent::build();
$active_theme = $this->themeManager
->getActiveTheme();
$theme_name = $active_theme->getName();
$destination = $this->redirectDestination
->get();
$visible_regions = $this->getVisibleRegionNames($theme_name);
// Build an array of the region names in the right order.
$build += array_fill_keys(array_keys($visible_regions), []);
foreach ($visible_regions as $region => $region_name) {
$query = [
'region' => $region,
];
if ($destination) {
$query['destination'] = $destination;
}
$title = $this->t('<span class="visually-hidden">Place block in the %region region</span>', [
'%region' => $region_name,
]);
$operations['block_description'] = [
'#type' => 'inline_template',
'#template' => '<div class="block-place-region">{{ link }}</div>',
'#context' => [
'link' => Link::createFromRoute($title, 'block.admin_library', [
'theme' => $theme_name,
], [
'query' => $query,
'attributes' => [
'title' => $title,
'class' => [
'use-ajax',
'button',
'button--small',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 700,
]),
],
]),
],
];
$build[$region] = [
'block_place_operations' => $operations,
] + $build[$region];
}
$build['#attached']['library'][] = 'block_place/drupal.block_place';
return $build;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.