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