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