You are here

function template_preprocess_views_tree_table in Views tree 8.2

Prepares variables for a views tree table display.

File

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

Code

function template_preprocess_views_tree_table(array &$variables) {

  // Set variables from core's table display.
  template_preprocess_views_view_table($variables);
  $view = $variables['view'];
  $rows = $variables['rows'];
  $options = $view
    ->getStyle()->options;

  // Add a class to the main field cell.
  foreach ($rows as $key => $row) {
    $row['columns'][$options['display_hierarchy_column']]['attributes']
      ->addClass('views-tree-hierarchy-cell');
    $rows[$key] = $row;
  }
  $tree_service = \Drupal::service('views_tree.tree');
  $variables['items'] = $tree_service
    ->buildRenderTree($view, $rows);

  // Since an HTML table isn't representative of a hierarchy, add data
  // data attributes for this representation.
  $tree_service
    ->addDataAttributes($variables['items']);

  // Attach layout library.
  $variables['#attached']['library'][] = 'views_tree/views_tree_table';
}