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_treeCode
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);
}
}