You are here

function template_preprocess_views_tree in Views tree 8.2

Prepares variables for a views tree display.

Parameters

array $variables: The variables to pass on to the template.

File

./views_tree.module, line 42
Views tree module.

Code

function template_preprocess_views_tree(array &$variables) {
  $rows = $variables['rows'];

  /** @var \Drupal\views\ViewExecutable $view */
  $view = $variables['view'];
  $options = $view
    ->getStyle()->options;
  $variables['#attached']['library'][] = 'views_tree/views_tree';

  // Add JS and CSS for collapsible tree, if configured.
  if (!empty($options['collapsible_tree'])) {
    $variables['#attached']['drupalSettings'] = [
      'views_tree_settings' => [
        [
          $view
            ->id(),
          $options['collapsible_tree'],
        ],
      ],
    ];
  }
  $variables['options'] = $options;
  $variables['list_type'] = $options['type'];

  /** @var \Drupal\views_tree\TreeHelper $tree_helper */
  $tree_helper = \Drupal::service('views_tree.tree');
  $variables['items'] = $tree_helper
    ->buildRenderTree($view, $rows);
}