ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
disabled.php File Reference

Go to the source code of this file.

Functions

 disabled ()
 Example showing how disabled groups can be used. More...
 

Function Documentation

◆ disabled()

disabled ( )

Example showing how disabled groups can be used.

Definition at line 5 of file disabled.php.

References $data, $DIC, $lng, and $result.

6 {
7  //Step 0: Declare dependencies
8  global $DIC;
9  $ui = $DIC->ui()->factory();
10  $lng = $DIC->language();
11  $renderer = $DIC->ui()->renderer();
12  $request = $DIC->http()->request();
13  $data = new \ILIAS\Data\Factory();
14  $refinery = $DIC->refinery();
15 
16  //Step 1: Implement transformation and constraints
17  $sum = $refinery->custom()->transformation(function ($vs) {
18  list($l, $r) = $vs;
19  $s = $l + $r;
20  return $s;
21  });
22  $equal_ten = $refinery->custom()->constraint(function ($v) {
23  return $v == 10;
24  }, "The sum must equal ten.");
25 
26  //Step 2: Define inputs
27  $number_input = $ui->input()->field()->numeric("number", "Cannot put in a number.")->withValue(5);
28 
29  //Step 3: Define the group, add the inputs to the group and attach the
30  //transformation and constraint
31  $group = $ui->input()->field()->group(
32  [ $number_input->withLabel("Left"), $number_input->withLabel("Right")]
33  )->withDisabled(true)
34  ->withAdditionalTransformation($sum)
35  ->withAdditionalTransformation($equal_ten);
36 
37  //Step 4: define form and form actions, attach the group to the form
38  $form = $ui->input()->container()->form()->standard('#', ["custom_group" => $group]);
39 
40  //Step 4: Implement some form data processing.
41  if ($request->getMethod() == "POST") {
42  //Step 4.1: Device some context dependant logic to display the potential
43  // constraint error on the group.
44  $form = $form->withRequest($request);
45  $group = $form->getInputs()["custom_group"];
46  if ($group->getError()) {
47  $result = $group->getError();
48  } else {
49  //The result is sumarized through the transformation
50  $result = $form->getData();
51  }
52  } else {
53  $result = "No result yet.";
54  }
55 
56  //Step 5: Return the rendered form
57  return
58  "<pre>" . print_r($result, true) . "</pre><br/>" .
59  $renderer->render($form);
60 }
$data
Definition: storeScorm.php:23
$result
$lng
$DIC
Definition: xapitoken.php:46