/** * 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')]); } }
/** * {@inheritdoc} */ protected function preprocessVariables(Variables $variables, $hook, array $info) { // Handle collapsible state. if ($variables['heading'] && $variables['collapsible']) { // Retrieve the panel ID, generating one if needed. $id = $variables->getAttribute('id', Html::getUniqueId('bootstrap-panel')); // 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); }