/** * Converts any set description variable into a traversable array. * * @param \Drupal\materialize\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')]); } }