file PrerenderManager.php

Namespace

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

Classes

Name Description
PrerenderManager Manages discovery and instantiation of Bootstrap pre-render callbacks.