3 namespace Drupal\bootstrap\Plugin\Preprocess;
5 use Drupal\bootstrap\Utility\Variables;
6 use Drupal\Component\Utility\Html;
9 * Pre-processes variables for the "bootstrap_modal" theme hook.
11 * @ingroup plugins_preprocess
13 * @BootstrapPreprocess("bootstrap_modal")
15 class BootstrapModal extends PreprocessBase implements PreprocessInterface {
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.'));
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']);
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);
38 // Use a provided modal size or retrieve the default theme setting.
39 $variables->size = $variables->size ?: $this->theme->getSetting('modal_size');
41 // Convert the description variable.
42 $this->preprocessDescription();
44 // Ensure all attributes are proper objects.
45 $this->preprocessAttributes();