function protected function BootstrapModal::preprocessVariables

8.x-3.x BootstrapModal.php protected BootstrapModal::preprocessVariables(Variables $variables)

Preprocess the variables array.

Parameters

\Drupal\bootstrap\Utility\Variables $variables: The Variables object.

Overrides PreprocessBase::preprocessVariables

Class

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

Namespace

Drupal\bootstrap\Plugin\Preprocess

Source src/Plugin/Preprocess/BootstrapModal.php (line 20)

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();
}