You are here

public function TreeHelper::addDataAttributes in Views tree 8.2

Adds hierarchical data attributes to the tree data.

File

src/TreeHelper.php, line 46

Class

TreeHelper
The tree helper service.

Namespace

Drupal\views_tree

Code

public function addDataAttributes(TreeItem $tree, $nesting = 0) {
  $node = $tree
    ->getNode();
  if (isset($node['attributes']) && $node['attributes'] instanceof Attribute) {
    $node['attributes']
      ->setAttribute('data-hierarchy-level', $nesting);
  }
  $nesting++;
  foreach ($tree
    ->getLeaves() as $leaf) {
    $this
      ->addDataAttributes($leaf, $nesting);
  }
}