/** * {@inheritdoc} */ protected function preprocessVariables(Variables $variables, $hook, array $info) { // Retrieve the ID, generating one if needed. $id = $variables->getAttribute('id', Html::getUniqueId($variables->offsetGet('id', 'bootstrap-panel'))); unset($variables['id']); // Handle collapsible state. if ($variables['heading'] && $variables['collapsible']) { // Retrieve the body ID attribute. if ($body_id = $variables->getAttribute('id', "{$id}--content", 'body_attributes')) { // Ensure the target is set. if ($variables['target'] = $variables->offsetGet('target', "#{$body_id}")) { // Set additional necessary attributes to the heading. $variables->setAttributes(['aria-controls' => preg_replace('/^#/', '', $variables['target']), 'aria-expanded' => !$variables['collapsed'] ? 'true' : 'false', 'aria-pressed' => !$variables['collapsed'] ? 'true' : 'false', 'data-toggle' => 'collapse', 'role' => 'button'], 'heading_attributes'); } } } // Ensure there is a valid panel state. if (!$variables->offsetGet('panel_type')) { $variables->offsetSet('panel_type', 'default'); } // Convert the description variable. $this->preprocessDescription($variables, $hook, $info); // Ensure all attributes are proper objects. $this->preprocessAttributes($variables, $hook, $info); }
/** * {@inheritdoc} */ protected function preprocessVariables(Variables $variables, $hook, array $info) { // Retrieve the ID, generating one if needed. $id = $variables->getAttribute('id', Html::getUniqueId($variables->offsetGet('id', 'bootstrap-carousel'))); unset($variables['id']); // Build slides. foreach ($variables->slides as $key => &$slide) { if (!isset($slide['attributes'])) { $slide['attributes'] = []; } $slide['attributes'] = new Attribute($slide['attributes']); } // Build controls. if ($variables->controls) { $left_icon = Bootstrap::glyphicon('chevron-left'); $right_icon = Bootstrap::glyphicon('chevron-right'); $url = Url::fromUserInput("#{$id}"); $variables->controls = ['left' => ['#type' => 'link', '#title' => new FormattableMarkup(Element::create($left_icon)->render() . '<span class="sr-only">@text</span>', ['@text' => t('Previous')]), '#url' => $url, '#attributes' => ['class' => ['left', 'carousel-control'], 'role' => 'button', 'data-slide' => 'prev']], 'right' => ['#type' => 'link', '#title' => new FormattableMarkup(Element::create($right_icon)->render() . '<span class="sr-only">@text</span>', ['@text' => t('Next')]), '#url' => $url, '#attributes' => ['class' => ['right', 'carousel-control'], 'role' => 'button', 'data-slide' => 'next']]]; } // Build indicators. if ($variables->indicators) { $variables->indicators = ['#theme' => 'item_list__bootstrap_carousel_indicators', '#list_type' => 'ol', '#items' => array_keys($variables->slides), '#target' => "#{$id}", '#start_index' => $variables->start_index]; } // Ensure all attributes are proper objects. $this->preprocessAttributes($variables, $hook, $info); }
/** * {@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')]); } }