ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
OptionalGroup.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2017 Timon Amstutz <timon.amstutz@ilub.unibe.ch> Extended GPL, see
4 docs/LICENSE */
5 
7 
9 use ILIAS\UI\Component as C;
16 
20 class OptionalGroup extends Group implements Field\OptionalGroup
21 {
23  use Triggerer;
24 
28  protected $null_value_was_explicitly_set = false;
29 
33  protected function getConstraintForRequirement()
34  {
35  return null;
36  }
37 
41  protected function isClientSideValueOk($value) : bool
42  {
43  if ($value === null) {
44  return true;
45  }
46  return parent::isClientSideValueOk($value);
47  }
48 
49  public function withRequired($is_required)
50  {
51  return Input::withRequired($is_required);
52  }
53 
58  public function withValue($value)
59  {
60  if ($value === null) {
61  $clone = clone $this;
62  $clone->value = $value;
63  $clone->null_value_was_explicitly_set = true;
64  return $clone;
65  }
66  $clone = parent::withValue($value);
67  $clone->null_value_was_explicitly_set = false;
68  return $clone;
69  }
70 
74  public function getValue()
75  {
76  if ($this->null_value_was_explicitly_set) {
77  return null;
78  }
79  return parent::getValue();
80  }
81 
82 
86  public function withInput(InputData $post_input)
87  {
88  if ($this->getName() === null) {
89  throw new \LogicException("Can only collect if input has a name.");
90  }
91 
92  if (!$this->isDisabled()) {
93  $value = $post_input->getOr($this->getName(), null);
94  if ($value === null) {
95  $clone = $this->withValue(null);
96  // Ugly hack to prevent shortcutting behaviour of applyOperationsTo
97  $temp = $clone->is_required;
98  $clone->is_required = true;
99  $clone->content = $clone->applyOperationsTo(null);
100  $clone->is_required = $temp;
101  return $clone;
102  }
103  }
104  return parent::withInput($post_input);
105  }
106 }
isDisabled()
Is this input disabled?
withValue($value)
Get an input like this with another value displayed on the client side.
This describes a group of inputs.
Definition: Group.php:11
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
This describes optional group inputs.
getOr($name, $default)
Get a named value from the data and fallback to default if that name does not exist.
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:12
withRequired($is_required)
Get an input like this, but set the field to be required (or not).
getValue()
Get the value that is displayed in the input client side.mixed
withValue($value)
Get an input like this with another value displayed on the client side.
withRequired($is_required)
Get an input like this, but set the field to be required (or not).