class BootstrapModal

Pre-processes variables for the "bootstrap_modal" theme hook.

Plugin annotation

@BootstrapPreprocess("bootstrap_modal")

Hierarchy

Expanded class hierarchy of BootstrapModal

Related topics

Namespace

Drupal\bootstrap\Plugin\Preprocess
Source
class BootstrapModal extends PreprocessBase implements PreprocessInterface {

  /**
   * {@inheritdoc}
   */
  protected function preprocessVariables(Variables $variables) {
    // Immediately log an error and return if Bootstrap modals are not enabled.
    if (!$this->theme->getSetting('modal_enabled')) {
      \Drupal::logger('bootstrap')->error(t('Bootstrap modals are not enabled.'));
      return;
    }

    // Retrieve the ID, generating one if needed.
    $id = $variables->getAttribute('id', Html::getUniqueId($variables->offsetGet('id', 'bootstrap-modal')));
    $variables->setAttribute('id', $id);
    unset($variables['id']);

    if ($variables->title) {
      $title_id = $variables->getAttribute('id', "$id--title", $variables::TITLE);
      $variables->setAttribute('id', $title_id, $variables::TITLE);
      $variables->setAttribute('aria-labelledby', $title_id);
    }

    // Use a provided modal size or retrieve the default theme setting.
    $variables->size = $variables->size ? : $this->theme->getSetting('modal_size');

    // Convert the description variable.
    $this->preprocessDescription();

    // Ensure all attributes are proper objects.
    $this->preprocessAttributes();
  }

}

Members

Contains filters are case sensitive
Name Modifiers Type Description
BootstrapModal::preprocessVariables protected function Preprocess the variables array. Overrides PreprocessBase::preprocessVariables
PluginBase::$theme protected property The currently set theme object.
PluginBase::__construct public function
PreprocessBase::$hook protected property The theme hook invoked.
PreprocessBase::$info protected property The theme hook info array from the theme registry.
PreprocessBase::$variables protected property The Variables object.
PreprocessBase::preprocess public function Preprocess theme hook variables. Overrides PreprocessInterface::preprocess
PreprocessBase::preprocessAttributes protected function Ensures all attributes have been converted to an Attribute object.
PreprocessBase::preprocessDescription protected function Converts any set description variable into a traversable array.
PreprocessBase::preprocessElement protected function Preprocess the variables array if an element is present.