public function ChooseBlockController::build in Layout Builder Restrictions 8.2
Provides the UI for choosing a new block.
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.
Return value
array A render array.
Overrides ChooseBlockController::build
File
- src/
Controller/ ChooseBlockController.php, line 19
Class
- ChooseBlockController
- Defines a controller to choose a new block.
Namespace
Drupal\layout_builder_restrictions\ControllerCode
public function build(SectionStorageInterface $section_storage, $delta, $region) {
$build = parent::build($section_storage, $delta, $region);
// Retrieve defined Layout Builder Restrictions plugins.
$layout_builder_restrictions_manager = \Drupal::service('plugin.manager.layout_builder_restriction');
$restriction_plugins = $layout_builder_restrictions_manager
->getSortedPlugins();
foreach (array_keys($restriction_plugins) as $id) {
$plugin = $layout_builder_restrictions_manager
->createInstance($id);
$allowed_inline_blocks = $plugin
->inlineBlocksAllowedinContext($section_storage, $delta, $region);
// If no inline blocks are allowed, remove the "Create custom block" link.
if (empty($allowed_inline_blocks)) {
unset($build['add_block']);
}
}
return $build;
}