ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
base.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
37function base()
38{
39 //Step 0: Declare dependencies
40 global $DIC;
41 $ui = $DIC->ui()->factory();
42 $lng = $DIC->language();
43 $renderer = $DIC->ui()->renderer();
44 $request = $DIC->http()->request();
45 $data = new \ILIAS\Data\Factory();
46 $refinery = new \ILIAS\Refinery\Factory($data, $lng);
47
48 //Step 1: Implement transformation and constraints
49 $sum = $refinery->custom()->transformation(function ($vs) {
50 list($l, $r) = $vs;
51 $s = $l + $r;
52 return $s;
53 });
54 $equal_ten = $refinery->custom()->constraint(function ($v) {
55 return $v == 10;
56 }, "The sum must equal ten");
57
58 //Step 2: Define inputs
59 $number_input = $ui->input()->field()->numeric("number", "Put in a number.");
60
61 //Step 3: Define the group, add the inputs to the group and attach the
62 //transformation and constraint
63 $group = $ui->input()->field()->section(
64 [ $number_input->withLabel("Left"), $number_input->withLabel("Right")],
65 "Equals 10",
66 "Left and Right must equal 10"
67 )
69 ->withAdditionalTransformation($equal_ten);
70
71 //Step 3, define form and form actions, attach the group to the form
72 $form = $ui->input()->container()->form()->standard('#', [$group]);
73
74 //Step 4, implement some form data processing.
75 if ($request->getMethod() == "POST") {
76 $form = $form->withRequest($request);
77 $result = $form->getData()[0] ?? "";
78 } else {
79 $result = "No result yet.";
80 }
81
82 //Return the rendered form
83 return
84 "<pre>" . print_r($result, true) . "</pre><br/>" .
85 $renderer->render($form);
86}
$renderer
withAdditionalTransformation(Transformation $trafo)
@inheritDoc
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26