ILIAS  release_8 Revision v8.23
disabled.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
11 function disabled()
12 {
13  //Step 0: Declare dependencies
14  global $DIC;
15  $ui = $DIC->ui()->factory();
16  $lng = $DIC->language();
17  $renderer = $DIC->ui()->renderer();
18  $request = $DIC->http()->request();
19  $data = new \ILIAS\Data\Factory();
20  $refinery = new \ILIAS\Refinery\Factory($data, $lng);
21 
22  //Step 1: Implement transformation and constraints
23  $sum = $refinery->custom()->transformation(function ($vs) {
24  list($l, $r) = $vs;
25  $s = $l + $r;
26  return $s;
27  });
28  $equal_ten = $refinery->custom()->constraint(function ($v) {
29  return $v == 10;
30  }, "The sum must equal ten");
31 
32  //Step 2: Define inputs
33  $number_input = $ui->input()->field()->numeric("number", "Put in a number.")->withValue(5);
34 
35  //Step 3: Define the group, add the inputs to the group and attach the
36  //transformation and constraint
37  $group = $ui->input()->field()->section(
38  [ $number_input->withLabel("Left"), $number_input->withLabel("Right")],
39  "Equals 10",
40  "Left and Right must equal 10"
41  )
43  ->withAdditionalTransformation($equal_ten)
44  ->withDisabled(true);
45 
46  //Step 3, define form and form actions, attach the group to the form
47  $form = $ui->input()->container()->form()->standard('#', [$group]);
48 
49  //Step 4, implement some form data processing.
50  if ($request->getMethod() == "POST") {
51  $form = $form->withRequest($request);
52  $result = $form->getData()[0];
53  } else {
54  $result = "No result yet.";
55  }
56 
57  //Return the rendered form
58  return
59  "<pre>" . print_r($result, true) . "</pre><br/>" .
60  $renderer->render($form);
61 }
$lng
disabled()
Example showing how disabled sections can be used to attach transformation and constraints on multipl...
Definition: disabled.php:11
global $DIC
Definition: feed.php:28
Refinery Factory $refinery