You are here

private function LayoutBuilder::createContextualLinkElement in Layout Builder Symmetric Translations 8

Creates contextual link element for a component.

Parameters

\Drupal\layout_builder\SectionStorageInterface $section_storage: The section storage.

$delta: The section delta.

$region: The region.

$uuid: The UUID of the component.

$is_translation: Whether the section storage is handling a translation.

Return value

array|null The contextual link render array or NULL if none.

1 call to LayoutBuilder::createContextualLinkElement()
LayoutBuilder::buildAdministrativeSection in src/Element/LayoutBuilder.php
Builds the render array for the layout section while editing.

File

src/Element/LayoutBuilder.php, line 134

Class

LayoutBuilder
Extended LayoutBuilder element to remove actions for translations.

Namespace

Drupal\layout_builder_st\Element

Code

private function createContextualLinkElement(SectionStorageInterface $section_storage, $delta, $region, $uuid) {
  $section = $section_storage
    ->getSection($delta);
  $contextual_link_settings = [
    'route_parameters' => [
      'section_storage_type' => $section_storage
        ->getStorageType(),
      'section_storage' => $section_storage
        ->getStorageId(),
      'delta' => $delta,
      'region' => $region,
      'uuid' => $uuid,
    ],
  ];
  if (static::isTranslation($section_storage)) {
    $contextual_group = 'layout_builder_block_translation';
    $component = $section
      ->getComponent($uuid);

    /** @var \Drupal\Core\Language\LanguageInterface $language */
    $language = $section_storage
      ->getTranslationLanguage();
    $contextual_link_settings['route_parameters']['langcode'] = $language
      ->getId();

    /** @var \Drupal\layout_builder\Plugin\Block\InlineBlock $plugin */
    $plugin = $component
      ->getPlugin();
    if ($plugin instanceof DerivativeInspectionInterface && $plugin
      ->getBaseId() === 'inline_block') {
      $configuration = $plugin
        ->getConfiguration();

      /** @var \Drupal\block_content\Entity\BlockContent $block */
      $block = $this->entityTypeManager
        ->getStorage('block_content')
        ->loadRevision($configuration['block_revision_id']);
      if ($block
        ->isTranslatable()) {
        $contextual_group = 'layout_builder_inline_block_translation';
      }
    }
  }
  else {
    $contextual_group = 'layout_builder_block';

    // Add metadata about the current operations available in
    // contextual links. This will invalidate the client-side cache of
    // links that were cached before the 'move' link was added.
    // @see layout_builder.links.contextual.yml
    $contextual_link_settings['metadata'] = [
      'operations' => 'move:update:remove',
    ];
  }
  return [
    $contextual_group => $contextual_link_settings,
  ];
}