Version 1
[yaffs-website] / web / themes / contrib / bootstrap / src / Plugin / PrerenderManager.php
1 <?php
2 /**
3  * @file
4  * Contains \Drupal\bootstrap\Plugin\PrerenderManager.
5  */
6
7 namespace Drupal\bootstrap\Plugin;
8
9 use Drupal\bootstrap\Theme;
10 use Drupal\bootstrap\Utility\Element;
11
12 /**
13  * Manages discovery and instantiation of Bootstrap pre-render callbacks.
14  *
15  * @ingroup plugins_prerender
16  */
17 class PrerenderManager extends PluginManager {
18
19   /**
20    * Constructs a new \Drupal\bootstrap\Plugin\PrerenderManager object.
21    *
22    * @param \Drupal\bootstrap\Theme $theme
23    *   The theme to use for discovery.
24    */
25   public function __construct(Theme $theme) {
26     parent::__construct($theme, 'Plugin/Prerender', 'Drupal\bootstrap\Plugin\Prerender\PrerenderInterface', 'Drupal\bootstrap\Annotation\BootstrapPrerender');
27     $this->setCacheBackend(\Drupal::cache('discovery'), 'theme:' . $theme->getName() . ':prerender', $this->getCacheTags());
28   }
29
30   /**
31    * Pre-render render array element callback.
32    *
33    * @param array $element
34    *   The render array element.
35    *
36    * @return array
37    *   The modified render array element.
38    */
39   public static function preRender(array $element) {
40     if (!empty($element['#bootstrap_ignore_pre_render'])) {
41       return $element;
42     }
43
44     $e = Element::create($element);
45
46     if ($e->isType('machine_name')) {
47       $e->addClass('form-inline', 'wrapper_attributes');
48     }
49
50     // Add smart descriptions to the element, if necessary.
51     $e->smartDescription();
52
53     return $element;
54   }
55
56 }