ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
expandable.php File Reference

Go to the source code of this file.

Functions

 expandable ()
 

Function Documentation

◆ expandable()

expandable ( )

Definition at line 2 of file expandable.php.

References $data, $DIC, Vendor\Package\$f, $factory, and ILIAS\UI\Component\Clickable\withOnClick().

Referenced by ilStyleTableGUI\__construct().

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
42  ) : \ILIAS\UI\Component\Tree\Node\Node {
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 }
Class Factory.
$data
Definition: storeScorm.php:23
Class ChatMainBarProvider .
global $DIC
Definition: goto.php:24
$factory
Definition: metadata.php:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function: