You are here

protected function LayoutBuilderRestrictionsSubscriber::alterBlockChooser in Layout Builder Restrictions 8

Alters the block providers available in Layout Builder's choose_block.

Parameters

array $result: Controller result.

1 call to LayoutBuilderRestrictionsSubscriber::alterBlockChooser()
LayoutBuilderRestrictionsSubscriber::onKernelView in src/EventSubscriber/LayoutBuilderRestrictionsSubscriber.php
Subscriber for kernel view.

File

src/EventSubscriber/LayoutBuilderRestrictionsSubscriber.php, line 91

Class

LayoutBuilderRestrictionsSubscriber
Layout builder restrictions event subscriber.

Namespace

Drupal\layout_builder_restrictions\EventSubscriber

Code

protected function alterBlockChooser(array &$result) {
  if (interface_exists('Drupal\\Core\\Plugin\\FilteredPluginManagerInterface')) {

    // This will now be altered through the appropriate new hooks. We still
    // fire the chooser result hook, since this is still a place where one
    // could put other things like extra css or extra content.
    $this->moduleHandler
      ->alter('layout_builder_restrictions_chooser_result', $result);
    return;
  }
  $keys = $this->moduleHandler
    ->invokeAll('layout_builder_restrictions_allowed_block_keys');
  if (!empty($keys)) {
    $this->moduleHandler
      ->alter('layout_builder_restrictions_allowed_block_keys', $keys);
    foreach (Element::children($result) as $delta) {
      if (!in_array($delta, $keys)) {
        $result[$delta]['#access'] = FALSE;
      }
    }
  }
  $this->moduleHandler
    ->alter('layout_builder_restrictions_chooser_result', $result);
}