LayoutBuilderModal.php in Layout Builder Modal 8
File
src/LayoutBuilderModal.php
View source
<?php
namespace Drupal\layout_builder_modal;
use Drupal\Core\Security\TrustedCallbackInterface;
class LayoutBuilderModal implements TrustedCallbackInterface {
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'])) {
$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;
}
public static function trustedCallbacks() {
return [
'preRenderContextual',
];
}
}