You are here

function simple_block_layout_builder_contextual_links_alter in Simple Block 8

Implements hook_contextual_links_alter().

File

modules/simple_block_layout_builder/simple_block_layout_builder.module, line 24
Hook implementations for 'Simple Block + Layout Builder' module.

Code

function simple_block_layout_builder_contextual_links_alter(array &$links, $group, array $route_parameters) : void {
  if ($group !== 'layout_builder_block' || !isset($links['layout_builder_block_update'])) {
    return;
  }
  $params =& $links['layout_builder_block_update']['route_parameters'];
  if (!($display = \Drupal::entityTypeManager()
    ->getStorage('entity_view_display')
    ->load($params['section_storage']))) {

    // @todo Support for other kind of layout builders, such as lb_everywhere?
    return;
  }

  /** @var \Drupal\layout_builder\SectionStorage\SectionStorageManager $section_manager */
  $section_manager = \Drupal::service('plugin.manager.layout_builder.section_storage');
  $section_storage = $section_manager
    ->load($params['section_storage_type'], [
    'display' => EntityContext::fromEntity($display),
  ]);

  /** @var \Drupal\layout_builder\SectionStorageInterface $temp_storage */
  $temp_storage = \Drupal::service('layout_builder.tempstore_repository')
    ->get($section_storage);
  $section = $temp_storage
    ->getSection($params['delta']);
  $components = $section
    ->getComponents();
  if (!isset($components[$params['uuid']])) {
    return;
  }
  $plugin = $components[$params['uuid']]
    ->getPlugin();
  if ($plugin
    ->getBaseId() === 'simple_block') {
    $links['layout_builder_block_update']['route_name'] = 'simple_block_layout_builder.edit_block';
    $params['simple_block'] = $plugin
      ->getDerivativeId();
  }
}