ILIAS  release_8 Revision v8.24
expandable2.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6
7function expandable2(): string
8{
9 global $DIC;
10 $f = $DIC->ui()->factory();
11 $renderer = $DIC->ui()->renderer();
12
13 $getDataNode = function (string $label, array $children = []) {
14 return new class ($label, $children) {
15 protected string $label = '';
16 protected array$children = [];
17
18 public function __construct(string $label, array $children = [])
19 {
20 $this->label = $label;
21 $this->children = $children;
22 }
23
24 public function getLabel(): string
25 {
26 return $this->label;
27 }
28
29 public function getChildren(): array
30 {
31 return $this->children;
32 }
33 };
34 };
35
36 $n11 = $getDataNode('1.1');
37 $n12 = $getDataNode('1.2', [$getDataNode('1.2.1')]);
38 $n1 = $getDataNode('1', [$n11, $n12]);
39 $data = [$n1];
40
41 $recursion = new class () implements \ILIAS\UI\Component\Tree\TreeRecursion {
42 public function getChildren($record, $environment = null): array
43 {
44 return $record->getChildren();
45 }
46
47 public function build(
49 $record,
50 $environment = null
52 return $factory->simple($record->getLabel());
53 }
54 };
55
56 $tree = $f->tree()->expandable("Label", $recursion)
57 ->withData($data);
58
59 return $renderer->render($tree);
60}
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:62
This describes a Tree Node.
Definition: Node.php:31
This is how the factory for UI elements looks.
Definition: Factory.php:38
$factory
Definition: metadata.php:75
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.