Skip to content

Commit 5f20dd5

Browse files
committed
ENH Add aria attrs to site tree
1 parent 9c59c42 commit 5f20dd5

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/ORM/Hierarchy/MarkedSet.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ protected function getSubtree($node, $depth = 0)
420420
'expanded' => $expanded,
421421
'opened' => $opened,
422422
'depth' => $depth,
423+
'level' => $depth + 1,
423424
'count' => $count, // Count of DB children
424425
'limited' => $limited, // Flag whether 'items' has been limited
425426
'children' => [], // Children to return in this request

tests/php/ORM/MarkedSetTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,32 @@ public function testGetChildrenAsULNodeDeletedOnStage()
382382
$this->assertEquals('unexpanded jstree-closed closed', $nodeClass, 'obj2 should have children in the sitetree');
383383
}
384384

385+
public function testGetChildrenAsArrayIncludesLevel(): void
386+
{
387+
$obj3 = $this->objFromFixture(HierarchyTest\TestObject::class, 'obj3');
388+
$obj3a = $this->objFromFixture(HierarchyTest\TestObject::class, 'obj3a');
389+
$obj3aa = $this->objFromFixture(HierarchyTest\TestObject::class, 'obj3aa');
390+
391+
$set = new MarkedSet(HierarchyTest\TestObject::singleton(), 'AllChildrenIncludingDeleted', 'numChildren');
392+
$set->markPartialTree();
393+
$set->markToExpose($obj3aa);
394+
395+
$tree = $set->getChildrenAsArray(function ($node) {
396+
return [
397+
'id' => $node->ID,
398+
'title' => $node->Title,
399+
];
400+
});
401+
$node3 = $this->findTreeNodeById($tree, $obj3->ID);
402+
$node3a = $this->findTreeNodeById($tree, $obj3a->ID);
403+
$node3aa = $this->findTreeNodeById($tree, $obj3aa->ID);
404+
405+
$this->assertSame(1, $tree['level']);
406+
$this->assertSame(2, $node3['level']);
407+
$this->assertSame(3, $node3a['level']);
408+
$this->assertSame(4, $node3aa['level']);
409+
}
410+
385411

386412
/**
387413
* @param string $html [description]
@@ -436,6 +462,22 @@ protected function getNodeClassFromTree($html, $node)
436462
return '';
437463
}
438464

465+
protected function findTreeNodeById(array $tree, int $id): array
466+
{
467+
if (($tree['id'] ?? null) === $id) {
468+
return $tree;
469+
}
470+
471+
foreach ($tree['children'] ?? [] as $child) {
472+
$result = $this->findTreeNodeById($child, $id);
473+
if ($result) {
474+
return $result;
475+
}
476+
}
477+
478+
return [];
479+
}
480+
439481
protected function assertHTMLSame($expected, $actual, $message = '')
440482
{
441483
// Trim each line, strip empty lines

0 commit comments

Comments
 (0)