ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
disabled.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
39 function disabled()
40 {
41  //Step 0: Declare dependencies
42  global $DIC;
43  $ui = $DIC->ui()->factory();
44  $lng = $DIC->language();
45  $renderer = $DIC->ui()->renderer();
46  $request = $DIC->http()->request();
47  $data = new \ILIAS\Data\Factory();
48  $refinery = $DIC->refinery();
49 
50  //Step 1: Implement transformation and constraints
51  $sum = $refinery->custom()->transformation(function ($vs) {
52  list($l, $r) = $vs;
53  $s = $l + $r;
54  return $s;
55  });
56  $equal_ten = $refinery->custom()->constraint(function ($v) {
57  return $v == 10;
58  }, "The sum must equal ten.");
59 
60  //Step 2: Define inputs
61  $number_input = $ui->input()->field()->numeric("number", "Cannot put in a number.")->withValue(5);
62 
63  //Step 3: Define the group, add the inputs to the group and attach the
64  //transformation and constraint
65  $group = $ui->input()->field()->group(
66  [ $number_input->withLabel("Left"), $number_input->withLabel("Right")]
67  )->withDisabled(true)
68  ->withAdditionalTransformation($sum)
69  ->withAdditionalTransformation($equal_ten);
70 
71  //Step 4: define form and form actions, attach the group to the form
72  $form = $ui->input()->container()->form()->standard('#', ["custom_group" => $group]);
73 
74  //Step 4: Implement some form data processing.
75  if ($request->getMethod() == "POST") {
76  //Step 4.1: Device some context dependant logic to display the potential
77  // constraint error on the group.
78  $form = $form->withRequest($request);
79  $group = $form->getInputs()["custom_group"];
80  if ($group->getError()) {
81  $result = $group->getError();
82  } else {
83  //The result is summarized through the transformation
84  $result = $form->getData();
85  }
86  } else {
87  $result = "No result yet.";
88  }
89 
90  //Step 5: Return the rendered form
91  return
92  "<pre>" . print_r($result, true) . "</pre><br/>" .
93  $renderer->render($form);
94 }
$renderer
disabled()
description: > Example showing how disabled groups can be used.
Definition: disabled.php:39
global $DIC
Definition: shib_login.php:22
global $lng
Definition: privfeed.php:31
$r