5 * Provides hook implementations for Layout Discovery.
8 use Drupal\Core\Render\Element;
9 use Drupal\Core\Template\Attribute;
12 * Implements hook_help().
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>';
25 * Implements hook_theme().
27 function layout_discovery_theme() {
28 return \Drupal::service('plugin.manager.core.layout')->getThemeImplementations();
32 * Prepares variables for layout templates.
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.
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'] : [];
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'] = [];
48 $variables['region_attributes'][$name] = new Attribute($variables['content'][$name]['#attributes']);