4 * Contains \Drupal\bootstrap\Plugin\Preprocess\BootstrapModal.
7 namespace Drupal\bootstrap\Plugin\Preprocess;
9 use Drupal\bootstrap\Annotation\BootstrapPreprocess;
10 use Drupal\bootstrap\Utility\Variables;
11 use Drupal\Component\Utility\Html;
14 * Pre-processes variables for the "bootstrap_modal" theme hook.
16 * @ingroup plugins_preprocess
18 * @BootstrapPreprocess("bootstrap_modal")
20 class BootstrapModal extends PreprocessBase implements PreprocessInterface {
25 protected function preprocessVariables(Variables $variables) {
26 // Immediately log an error and return if Bootstrap modals are not enabled.
27 if (!$this->theme->getSetting('modal_enabled')) {
28 \Drupal::logger('bootstrap')->error(t('Bootstrap modals are not enabled.'));
32 // Retrieve the ID, generating one if needed.
33 $id = $variables->getAttribute('id', Html::getUniqueId($variables->offsetGet('id', 'bootstrap-modal')));
34 $variables->setAttribute('id', $id);
35 unset($variables['id']);
37 if ($variables->title) {
38 $title_id = $variables->getAttribute('id', "$id--title", $variables::TITLE);
39 $variables->setAttribute('id', $title_id, $variables::TITLE);
40 $variables->setAttribute('aria-labelledby', $title_id);
43 // Use a provided modal size or retrieve the default theme setting.
44 $variables->size = $variables->size ?: $this->theme->getSetting('modal_size');
46 // Convert the description variable.
47 $this->preprocessDescription();
49 // Ensure all attributes are proper objects.
50 $this->preprocessAttributes();