file BootstrapModal.php

Namespace

Drupal\bootstrap\Plugin\Preprocess
  1. <?php
  2. namespace Drupal\bootstrap\Plugin\Preprocess;
  3. use Drupal\bootstrap\Utility\Variables;
  4. use Drupal\Component\Utility\Html;
  5. /**
  6. * Pre-processes variables for the "bootstrap_modal" theme hook.
  7. *
  8. * @ingroup plugins_preprocess
  9. *
  10. * @BootstrapPreprocess("bootstrap_modal")
  11. */
  12. class BootstrapModal extends PreprocessBase implements PreprocessInterface {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. protected function preprocessVariables(Variables $variables) {
  17. // Immediately log an error and return if Bootstrap modals are not enabled.
  18. if (!$this->theme->getSetting('modal_enabled')) {
  19. \Drupal::logger('bootstrap')->error(t('Bootstrap modals are not enabled.'));
  20. return;
  21. }
  22. // Retrieve the ID, generating one if needed.
  23. $id = $variables->getAttribute('id', Html::getUniqueId($variables->offsetGet('id', 'bootstrap-modal')));
  24. $variables->setAttribute('id', $id);
  25. unset($variables['id']);
  26. if ($variables->title) {
  27. $title_id = $variables->getAttribute('id', "$id--title", $variables::TITLE);
  28. $variables->setAttribute('id', $title_id, $variables::TITLE);
  29. $variables->setAttribute('aria-labelledby', $title_id);
  30. }
  31. // Use a provided modal size or retrieve the default theme setting.
  32. $variables->size = $variables->size ?: $this->theme->getSetting('modal_size');
  33. // Convert the description variable.
  34. $this->preprocessDescription();
  35. // Ensure all attributes are proper objects.
  36. $this->preprocessAttributes();
  37. }
  38. }

Classes

Name Description
BootstrapModal Pre-processes variables for the "bootstrap_modal" theme hook.