file PrerenderManager.php

Namespace

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

Classes

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