/** * {@inheritdoc} */ public function preprocessVariables(Variables $variables) { // Ensure a unique ID, generating one if needed. $id = $variables->getAttribute('id', Html::getUniqueId($variables->offsetGet('id', 'progress-bar'))); $variables->setAttribute('id', $id); unset($variables['id']); // Preprocess attributes. $this->preprocessAttributes(); }
/** * {@inheritdoc} */ protected function preprocessVariables(Variables $variables, $hook, array $info) { // 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($variables, $hook, $info); // Ensure all attributes are proper objects. $this->preprocessAttributes($variables, $hook, $info); }
/** * Converts any set description variable into a traversable array. * * @param \Drupal\bootstrap\Utility\Variables $variables * A variables object. * @param string $hook * The name of the theme hook. * @param array $info * The theme hook info array. * * @see https://www.drupal.org/node/2324025 */ protected function preprocessDescription(Variables $variables, $hook, array $info) { if ($variables->offsetGet('description')) { // Retrieve the description attributes. $description_attributes = $variables->offsetGet('description_attributes', []); // Remove standalone description attributes. $variables->offsetUnset('description_attributes'); // Build the description attributes. if ($id = $variables->getAttribute('id')) { $variables->setAttribute('aria-describedby', "{$id}--description"); $description_attributes['id'] = "{$id}--description"; } // Replace the description variable. $variables->offsetSet('description', ['attributes' => new Attribute($description_attributes), 'content' => $variables['description'], 'position' => $variables->offsetGet('description_display', 'after')]); } }