Security update to Drupal 8.4.6
[yaffs-website] / web / core / modules / layout_discovery / layout_discovery.module
1 <?php
2
3 /**
4  * @file
5  * Provides hook implementations for Layout Discovery.
6  */
7
8 use Drupal\Core\Render\Element;
9 use Drupal\Core\Template\Attribute;
10
11 /**
12  * Implements hook_help().
13  */
14 function layout_discovery_help($route_name) {
15   switch ($route_name) {
16     case 'help.page.layout_discovery':
17       $output = '<h3>' . t('About') . '</h3>';
18       $output .= '<p>' . t('Layout Discovery allows modules or themes to register layouts, and for other modules to list the available layouts and render them.') . '</p>';
19       $output .= '<p>' . t('For more information, see the <a href=":layout-discovery-documentation">online documentation for the Layout Discovery module</a>.', [':layout-discovery-documentation' => 'https://www.drupal.org/docs/8/api/layout-api']) . '</p>';
20       return $output;
21   }
22 }
23
24 /**
25  * Implements hook_theme().
26  */
27 function layout_discovery_theme() {
28   return \Drupal::service('plugin.manager.core.layout')->getThemeImplementations();
29 }
30
31 /**
32  * Prepares variables for layout templates.
33  *
34  * @param array &$variables
35  *   An associative array containing:
36  *   - content: An associative array containing the properties of the element.
37  *     Properties used: #settings, #layout.
38  */
39 function template_preprocess_layout(&$variables) {
40   $variables['settings'] = isset($variables['content']['#settings']) ? $variables['content']['#settings'] : [];
41   $variables['layout'] = isset($variables['content']['#layout']) ? $variables['content']['#layout'] : [];
42
43   // Create an attributes variable for each region.
44   foreach (Element::children($variables['content']) as $name) {
45     if (!isset($variables['content'][$name]['#attributes'])) {
46       $variables['content'][$name]['#attributes'] = [];
47     }
48     $variables['region_attributes'][$name] = new Attribute($variables['content'][$name]['#attributes']);
49   }
50 }