ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
expandable2.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
17 function expandable2(): string
18 {
19  global $DIC;
20  $f = $DIC->ui()->factory();
21  $renderer = $DIC->ui()->renderer();
22 
23  $getDataNode = function (string $label, array $children = []) {
24  return new class ($label, $children) {
25  protected string $label = '';
26  protected array $children = [];
27 
28  public function __construct(string $label, array $children = [])
29  {
30  $this->label = $label;
31  $this->children = $children;
32  }
33 
34  public function getLabel(): string
35  {
36  return $this->label;
37  }
38 
39  public function getChildren(): array
40  {
41  return $this->children;
42  }
43  };
44  };
45 
46  $n11 = $getDataNode('1.1');
47  $n12 = $getDataNode('1.2', [$getDataNode('1.2.1')]);
48  $n1 = $getDataNode('1', [$n11, $n12]);
49  $data = [$n1];
50 
51  $recursion = new class () implements \ILIAS\UI\Component\Tree\TreeRecursion {
52  public function getChildren($record, $environment = null): array
53  {
54  return $record->getChildren();
55  }
56 
57  public function build(
58  \ILIAS\UI\Component\Tree\Node\Factory $factory,
59  $record,
60  $environment = null
61  ): \ILIAS\UI\Component\Tree\Node\Node {
62  return $factory->simple($record->getLabel());
63  }
64  };
65 
66  $tree = $f->tree()->expandable("Label", $recursion)
67  ->withData($data);
68 
69  return $renderer->render($tree);
70 }
$renderer
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This is how the factory for UI elements looks.
Definition: Factory.php:37
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:76
expandable2()
description: > Example for rendering an expandable tree.
Definition: expandable2.php:17