52f271f8e717556f8caf7e97a9d9f056da67b000
[yaffs-website] / web / themes / contrib / bootstrap / src / Plugin / Preprocess / BootstrapModal.php
1 <?php
2 /**
3  * @file
4  * Contains \Drupal\bootstrap\Plugin\Preprocess\BootstrapModal.
5  */
6
7 namespace Drupal\bootstrap\Plugin\Preprocess;
8
9 use Drupal\bootstrap\Annotation\BootstrapPreprocess;
10 use Drupal\bootstrap\Utility\Variables;
11 use Drupal\Component\Utility\Html;
12
13 /**
14  * Pre-processes variables for the "bootstrap_modal" theme hook.
15  *
16  * @ingroup plugins_preprocess
17  *
18  * @BootstrapPreprocess("bootstrap_modal")
19  */
20 class BootstrapModal extends PreprocessBase implements PreprocessInterface {
21
22   /**
23    * {@inheritdoc}
24    */
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.'));
29       return;
30     }
31
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']);
36
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);
41     }
42
43     // Use a provided modal size or retrieve the default theme setting.
44     $variables->size = $variables->size ?: $this->theme->getSetting('modal_size');
45
46     // Convert the description variable.
47     $this->preprocessDescription();
48
49     // Ensure all attributes are proper objects.
50     $this->preprocessAttributes();
51   }
52
53 }