You are here

protected function LayoutBuilder::buildAdministrativeSection in Layout Builder Symmetric Translations 8

Builds the render array for the layout section while editing.

Parameters

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

int $delta: The delta of the section.

Return value

array The render array for a given section.

Overrides LayoutBuilder::buildAdministrativeSection

File

src/Element/LayoutBuilder.php, line 79

Class

LayoutBuilder
Extended LayoutBuilder element to remove actions for translations.

Namespace

Drupal\layout_builder_st\Element

Code

protected function buildAdministrativeSection(SectionStorageInterface $section_storage, $delta) {
  $section_build = parent::buildAdministrativeSection($section_storage, $delta);
  $this
    ->setTranslationAcess($section_build['remove'], $section_storage);
  $this
    ->setTranslationAcess($section_build['configure'], $section_storage);
  if (static::isTranslation($section_storage)) {
    foreach (Element::children($section_build['layout-builder__section']) as $region) {
      $region_build =& $section_build['layout-builder__section'][$region];
      $this
        ->setTranslationAcess($region_build['layout_builder_add_block'], $section_storage);
      foreach (Element::children($region_build) as $uuid) {
        if (substr_count($uuid, '-') !== 4) {
          continue;
        }

        // Remove class that enables drag and drop.
        // @todo Can we remove drag and drop in JS?
        if (($key = array_search('js-layout-builder-block', $region_build[$uuid]['#attributes']['class'])) !== FALSE) {
          unset($region_build[$uuid]['#attributes']['class'][$key]);
        }
        if ($contextual_link_element = $this
          ->createContextualLinkElement($section_storage, $delta, $region, $uuid)) {
          $region_build[$uuid]['#contextual_links'] = $contextual_link_element;
        }
        else {
          unset($region_build[$uuid]['#contextual_links']);
        }
      }
    }
  }
  return $section_build;
}