ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
expandable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
33function expandable()
34{
35 global $DIC;
36 $f = $DIC->ui()->factory();
37 $renderer = $DIC->ui()->renderer();
38
39 $data = [
40 ['label' => 'root', 'children' => [
41 ['label' => '1', 'children' => [
42 ['label' => '1.1', 'children' => [
43 ['label' => '1.1.1', 'children' => []],
44 ['label' => '1.1.2', 'children' => []]
45 ]],
46 ['label' => '1.2', 'children' => []],
47 ['label' => '1.3', 'children' => []]
48 ]],
49 ['label' => '2', 'children' => [
50 ['label' => '2.1', 'children' => []],
51 ]],
52 ['label' => '3', 'children' => [
53 ['label' => '3.1', 'children' => [
54 ['label' => '3.1.1', 'children' => [
55 ['label' => '3.1.1.1', 'children' => []],
56 ]],
57 ]],
58
59 ]],
60 ]]
61 ];
62
63 $recursion = new class () implements \ILIAS\UI\Component\Tree\TreeRecursion {
64 public function getChildren($record, $environment = null): array
65 {
66 return $record['children'];
67 }
68
69 public function build(
70 \ILIAS\UI\Component\Tree\Node\Factory $factory,
71 $record,
72 $environment = null
74 $label = $record['label'];
75 $node = $factory->simple($label);
76
77 if (count($record['children']) === 0) {
78 $node = $node->withOnClick($environment['modal']->getShowSignal());
79 }
80
81 if ($label === "root" || $label === "2") {
82 $node = $node->withExpanded(true);
83 }
84 if ($label === "2") {
85 $node = $node->withHighlighted(true);
86 }
87
88 return $node;
89 }
90 };
91
92 $image = $f->image()->responsive("assets/ui-examples/images/Image/mountains.jpg", "Image source: https://stocksnap.io, Creative Commons CC0 license");
93 $page = $f->modal()->lightboxImagePage($image, 'Mountains');
94 $modal = $f->modal()->lightbox($page);
95 $environment = [
96 'modal' => $modal
97 ];
98
99 $tree = $f->tree()->expandable("Label", $recursion)
100 ->withEnvironment($environment)
101 ->withData($data)
102 ->withHighlightOnNodeClick(true);
103
104 return $renderer->render([
105 $modal,
106 $tree
107 ]);
108}
$renderer
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Definition: UI.php:24
withOnClick(Signal $signal)
Get a component like this, triggering a signal of another component on click.
This describes a Tree Node.
Definition: Node.php:31
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.