class LayoutDiscoveryThemeHooks

Theme hooks for layout_discovery.

Hierarchy

Expanded class hierarchy of LayoutDiscoveryThemeHooks

4 files declare their use of LayoutDiscoveryThemeHooks
LayoutPluginManager.php in core/lib/Drupal/Core/Layout/LayoutPluginManager.php
LayoutPluginManagerTest.php in core/tests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php
LayoutTest.php in core/modules/layout_discovery/tests/src/Kernel/LayoutTest.php
layout_discovery.module in core/modules/layout_discovery/layout_discovery.module

File

core/modules/layout_discovery/src/Hook/LayoutDiscoveryThemeHooks.php, line 13

Namespace

Drupal\layout_discovery\Hook
View source
class LayoutDiscoveryThemeHooks {
  public function __construct(protected LayoutPluginManagerInterface $layoutPluginManager) {
  }
  
  /**
   * Implements hook_theme().
   */
  public function theme() : array {
    return $this->layoutPluginManager
      ->getThemeImplementations();
  }
  
  /**
   * Prepares variables for layout templates.
   *
   * @param array &$variables
   *   An associative array containing:
   *   - content: An associative array containing the properties of the element.
   *     Properties used: #settings, #layout, #in_preview.
   */
  public function preprocessLayout(array &$variables) : void {
    $variables['settings'] = $variables['content']['#settings'] ?? [];
    $variables['layout'] = $variables['content']['#layout'] ?? [];
    $variables['in_preview'] = $variables['content']['#in_preview'] ?? FALSE;
    // Create an attributes variable for each region.
    foreach (Element::children($variables['content']) as $name) {
      if (!isset($variables['content'][$name]['#attributes'])) {
        $variables['content'][$name]['#attributes'] = [];
      }
      $variables['region_attributes'][$name] = new Attribute($variables['content'][$name]['#attributes']);
    }
  }

}

Members

Title Sort descending Modifiers Object type Summary
LayoutDiscoveryThemeHooks::preprocessLayout public function Prepares variables for layout templates.
LayoutDiscoveryThemeHooks::theme public function Implements hook_theme().
LayoutDiscoveryThemeHooks::__construct public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.