function template_preprocess_toc_back_to_top in TOC API 8
Prepares variables for back to top link.
Default template: toc-back-to-top.html.twig.
Parameters
array $variables: An associative array containing the following keys:
- toc: A TOC (table of contents) object.
- item: A table of contents header item.
- attributes: Attributes to be added to back to top link.
File
- ./
toc_api.module, line 92 - Converts header tags into a hierarchical table of contents.
Code
function template_preprocess_toc_back_to_top(&$variables) {
/** @var \Drupal\toc_api\TocInterface $toc */
$toc = $variables['toc'];
$options = $toc
->getOptions();
$variables['attributes']['href'] = '#top';
$variables['attributes'] = new Attribute($variables['attributes']);
$variables['label'] = $options['top_label'] ?: t('Back to top');
}