function protected function PreprocessBase::preprocessDescription

8.x-3.x PreprocessBase.php protected PreprocessBase::preprocessDescription()

Converts any set description variable into a traversable array.

Class

PreprocessBase
Base preprocess class used to build the necessary variables for templates.

Namespace

Drupal\bootstrap\Plugin\Preprocess

Source src/Plugin/Preprocess/PreprocessBase.php (line 72)

protected function preprocessDescription() {
  if ($this->variables->offsetGet('description')) {
    // Retrieve the description attributes.
    $description_attributes = $this->variables->offsetGet('description_attributes', []);

    // Remove standalone description attributes.
    $this->variables->offsetUnset('description_attributes');

    // Build the description attributes.
    if ($id = $this->variables->getAttribute('id')) {
      $this->variables->setAttribute('aria-describedby', "$id--description");
      $description_attributes['id'] = "$id--description";
    }

    // Replace the description variable.
    $this->variables->offsetSet('description', [
      'attributes' => new Attribute($description_attributes),
      'content' => $this->variables['description'],
      'position' => $this->variables->offsetGet('description_display', 'after'),
    ]);
  }
}