You are here

class LayoutBuilderModal in Layout Builder Modal 8

Class LayoutBuilderModal.

Hierarchy

Expanded class hierarchy of LayoutBuilderModal

1 file declares its use of LayoutBuilderModal
layout_builder_modal.module in ./layout_builder_modal.module
Contains layout_builder_modal.module.

File

src/LayoutBuilderModal.php, line 10

Namespace

Drupal\layout_builder_modal
View source
class LayoutBuilderModal implements TrustedCallbackInterface {

  /**
   * Adds contextual link metadata for Layout Builder Modal.
   *
   * @param array $element
   *   The Layout Builder render element.
   *
   * @return array
   *   The modified Layout Builder render element.
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  public static function trustedCallbacks() {
    return [
      'preRenderContextual',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LayoutBuilderModal::preRenderContextual public static function Adds contextual link metadata for Layout Builder Modal.
LayoutBuilderModal::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.