ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
reduce_with.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
37 function reduce_with()
38 {
39  global $DIC;
40  $ui = $DIC->ui()->factory();
41  $renderer = $DIC->ui()->renderer();
42 
43  $text_input = $ui->input()->field()
44  ->text("Required Input", "User needs to fill this field")
45  ->withRequired(true);
46 
47  $section = $ui->input()->field()->section(
48  [$text_input],
49  "Section with required field",
50  "The Form should show an explaining hint at the bottom"
51  );
52 
53  $form = $ui->input()->container()->form()->standard("", [$section, $section, $text_input]);
54 
55  $array = $form->reduceWith(
56  fn($c, $res) => [$c->getCanonicalName() => $res]
57  );
58 
59  return $renderer->render([
60  $ui->legacy()->content('<pre>' . print_r(json_encode($array, JSON_PRETTY_PRINT), true) . '</pre>'),
61  ]);
62 }
$res
Definition: ltiservices.php:66
$renderer
$c
Definition: deliver.php:25
global $DIC
Definition: shib_login.php:26
reduce_with()
description: > Example showing reduceWith-"catamorphism" with Form to factor out classes and structu...
Definition: reduce_with.php:37