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