function LayoutDiscoveryThemeHooks::preprocessLayout

Prepares variables for layout templates.

Parameters

array &$variables: An associative array containing:

  • content: An associative array containing the properties of the element. Properties used: #settings, #layout, #in_preview.

File

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

Class

LayoutDiscoveryThemeHooks
Theme hooks for layout_discovery.

Namespace

Drupal\layout_discovery\Hook

Code

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']);
  }
}

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