ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
expandable.php
Go to the documentation of this file.
1<?php
2function expandable()
3{
4 global $DIC;
5 $f = $DIC->ui()->factory();
6 $renderer = $DIC->ui()->renderer();
7
8 $data = [
9 ['label' => 'root', 'children' => [
10 ['label' => '1', 'children' => [
11 ['label' => '1.1', 'children' => [
12 ['label' => '1.1.1', 'children' => []],
13 ['label' => '1.1.2', 'children' => []]
14 ]],
15 ['label' => '1.2', 'children' => []],
16 ['label' => '1.3', 'children' => []]
17 ]],
18 ['label' => '2', 'children' => [
19 ['label' => '2.1', 'children' => []],
20 ]],
21 ['label' => '3', 'children' => [
22 ['label' => '3.1', 'children' => [
23 ['label' => '3.1.1', 'children' => [
24 ['label' => '3.1.1.1', 'children' => []],
25 ]],
26 ]],
27
28 ]],
29 ]]
30 ];
31
32 $recursion = new class implements \ILIAS\UI\Component\Tree\TreeRecursion {
33 public function getChildren($record, $environment = null) : array
34 {
35 return $record['children'];
36 }
37
38 public function build(
39 \ILIAS\UI\Component\Tree\Node\Factory $factory,
40 $record,
41 $environment = null
43 $label = $record['label'];
44 $node = $factory->simple($label);
45
46 if (count($record['children']) === 0) {
47 $node = $node->withOnClick($environment['modal']->getShowSignal());
48 }
49
50 if ($label === "root" || $label === "2") {
51 $node = $node->withExpanded(true);
52 }
53 if ($label === "2") {
54 $node = $node->withHighlighted(true);
55 }
56
57 return $node;
58 }
59 };
60
61 $image = $f->image()->responsive("src/UI/examples/Image/mountains.jpg", "Image source: https://stocksnap.io, Creative Commons CC0 license");
62 $page = $f->modal()->lightboxImagePage($image, 'Mountains');
63 $modal = $f->modal()->lightbox($page);
64 $environment = [
65 'modal' => $modal
66 ];
67
68 $tree = $f->tree()->expandable("Label", $recursion)
69 ->withEnvironment($environment)
70 ->withData($data)
71 ->withHighlightOnNodeClick(true);
72
73 return $renderer->render([
74 $modal,
75 $tree
76 ]);
77}
An exception for terminatinating execution or to throw for unit testing.
expandable()
Definition: expandable.php:2
This describes a Tree Node.
Definition: Node.php:16
$factory
Definition: metadata.php:58
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$data
Definition: storeScorm.php:23
$DIC
Definition: xapitoken.php:46