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