ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
key_value.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
18 function key_value()
19 {
20  global $DIC;
21  $f = $DIC->ui()->factory();
22  $renderer = $DIC->ui()->renderer();
23 
24  $icon = $f->symbol()->icon()->standard("crs", 'Example');
25  $long_value = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
26  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquy';
27 
28  $node1 = $f->tree()->node()->keyValue('label', 'value');
29  $node2 = $f->tree()->node()->keyValue('label', $long_value)
30  ->withLink(new \ILIAS\Data\URI('https://docu.ilias.de'));
31  $node3 = $f->tree()->node()->keyValue('label', 'value', $icon);
32  $node4 = $f->tree()->node()->keyValue('label', 'value', $icon)
33  ->withLink(new \ILIAS\Data\URI('https://docu.ilias.de'));
34  $data = [['node' => $node1, 'children' => [
35  ['node' => $node2]]],
36  ['node' => $node3, 'children' => [
37  ['node' => $node4]],
38  ]
39  ];
40 
41  $recursion = new class () implements \ILIAS\UI\Component\Tree\TreeRecursion {
42  public function getChildren($record, $environment = null): array
43  {
44  return $record['children'] ?? [];
45  }
46 
47  public function build(
48  \ILIAS\UI\Component\Tree\Node\Factory $factory,
49  $record,
50  $environment = null
51  ): \ILIAS\UI\Component\Tree\Node\Node {
52  $node = $record['node'];
53  if (isset($record['children'])) {
54  $node = $node->withExpanded(true);
55  }
56  return $node;
57  }
58  };
59 
60  $tree = $f->tree()->expandable('Label', $recursion)
61  ->withData($data);
62 
63  return $renderer->render($tree);
64 }
$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
key_value()
description: > Example for rendering a tree node with key values.
Definition: key_value.php:18
global $DIC
Definition: shib_login.php:25
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:34