Version 1
[yaffs-website] / web / themes / contrib / bootstrap / src / Plugin / Preprocess / Region.php
1 <?php
2 /**
3  * @file
4  * Contains \Drupal\bootstrap\Plugin\Preprocess\Region.
5  */
6
7 namespace Drupal\bootstrap\Plugin\Preprocess;
8
9 use Drupal\bootstrap\Annotation\BootstrapPreprocess;
10 use Drupal\bootstrap\Bootstrap;
11 use Drupal\bootstrap\Utility\Variables;
12
13 /**
14  * Pre-processes variables for the "region" theme hook.
15  *
16  * @ingroup plugins_preprocess
17  *
18  * @BootstrapPreprocess("region")
19  */
20 class Region extends PreprocessBase implements PreprocessInterface {
21
22   /**
23    * {@inheritdoc}
24    */
25   public function preprocessVariables(Variables $variables) {
26     $region = $variables['elements']['#region'];
27     $variables['region'] = $region;
28     $variables['content'] = $variables['elements']['#children'];
29
30     // Help region.
31     if ($region === 'help' && !empty($variables['content'])) {
32       $variables['content'] = [
33         'icon' => Bootstrap::glyphicon('question-sign'),
34         'content' => ['#markup' => $variables['content']],
35       ];
36       $variables->addClass(['alert', 'alert-info', 'messages', 'info']);
37     }
38
39     // Support for "well" classes in regions.
40     static $region_wells;
41     if (!isset($region_wells)) {
42       $region_wells = $this->theme->getSetting('region_wells');
43     }
44     if (!empty($region_wells[$region])) {
45       $variables->addClass($region_wells[$region]);
46     }
47   }
48
49 }