ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
4docs/LICENSE */
5
7
8use ILIAS\Data\Factory as DataFactory;
16
20class OptionalGroup extends Group implements Field\OptionalGroup
21{
23 use Triggerer;
24
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}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
withValue($value)
Get an input like this with another value displayed on the client side.InvalidArgumentException if va...
getValue()
Get the value that is displayed in the input client side.mixed
withRequired($is_required)
Get an input like this, but set the field to be required (or not).
A constraint encodes some resrtictions on values.
Definition: Constraint.php:15
A transformation is a function from one datatype to another.
This describes a group of inputs.
Definition: Group.php:12
withValue($value)
Get an input like this with another value displayed on the client side.
isDisabled()
Is this input disabled?
withRequired($is_required)
Get an input like this, but set the field to be required (or not).
This describes optional group inputs.
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:13
getOr($name, $default)
Get a named value from the data and fallback to default if that name does not exist.
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.