ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
with_value.php
Go to the documentation of this file.
1 <?php
2 
18 declare(strict_types=1);
19 
21 
33 function with_value(): string
34 {
35  global $DIC;
36  $factory = $DIC->ui()->factory();
37  $renderer = $DIC->ui()->renderer();
38 
39  $group_one = $factory->input()->field()->group([$factory->input()->field()->text("Item 1", "Just some field")], "Group 1");
40  $group_two = $factory->input()->field()->group([$factory->input()->field()->text("Item 2", "Just some field")], "Group 2");
41 
42  $switchable_group = $factory->input()->field()->switchableGroup(
43  [$group_one, $group_two],
44  "Switchable Group with existing value(s)",
45  );
46 
47  // tells the input only which option is selected
48  $direct_value = $switchable_group->withValue(1);
49 
50  // tells the input which option is selected and what value(s) it has
51  $nested_value = $switchable_group->withValue([1, ['some existing text value']]);
52 
53  $form = $factory->input()->container()->form()->standard('#', [$direct_value, $nested_value]);
54 
55  return $renderer->render($form);
56 }
$renderer
global $DIC
Definition: shib_login.php:26
with_value()
description: > Example showing two Switchable Group Fields provided with existing value(s)...
Definition: with_value.php:33