You are here

function template_preprocess_toc_header in TOC API 8

Prepares variables for table of contents header.

Default template: toc-header.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.

File

./toc_api.module, line 64
Converts header tags into a hierarchical table of contents.

Code

function template_preprocess_toc_header(&$variables) {

  /** @var \Drupal\toc_api\TocInterface $toc */
  $toc = $variables['toc'];
  $item = $variables['item'];
  $variables += $item;

  // Set options to the header specific options.
  $options = $toc
    ->getOptions();
  $variables['options'] = $options;
  $variables['header_options'] = $options['headers'][$item['tag']];
  $variables['header_options']['display_number'] = in_array($variables['header_options']['number_type'], [
    'decimal',
    'lower-alpha',
    'upper-alpha',
    'lower-roman',
    'upper-roman',
  ]);
  $variables['attributes']['id'] = $variables['id'];
  $variables['attributes'] = new Attribute($variables['attributes']);
}