You are here

public static function LayoutBuilderModal::preRenderContextual in Layout Builder Modal 8

Adds contextual link metadata for Layout Builder Modal.

Parameters

array $element: The Layout Builder render element.

Return value

array The modified Layout Builder render element.

File

src/LayoutBuilderModal.php, line 21

Class

LayoutBuilderModal
Class LayoutBuilderModal.

Namespace

Drupal\layout_builder_modal

Code

public static function preRenderContextual(array $element) {
  $config = \Drupal::config('layout_builder_modal.settings');
  $hash = hash('sha256', serialize($config
    ->getRawData()));
  foreach ($element['layout_builder'] as &$child_element) {
    if (isset($child_element['layout-builder__section'])) {

      /** @var \Drupal\Core\Layout\LayoutDefinition $layout_definition */
      $layout_definition = $child_element['layout-builder__section']['#layout'];
      foreach ($layout_definition
        ->getRegions() as $region => $info) {
        if (empty($child_element['layout-builder__section'][$region])) {
          continue;
        }
        foreach ($child_element['layout-builder__section'][$region] as &$section_child_element) {
          if (isset($section_child_element['#theme']) && $section_child_element['#theme'] === 'block') {
            $section_child_element['#contextual_links']['layout_builder_block']['metadata']['layout_builder_modal'] = $hash;
          }
        }
      }
    }
  }
  return $element;
}