ILIAS  release_7 Revision v7.30-3-g800a261c036
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
54 public function isRequired(): bool
55 {
56 return $this->is_required;
57 }
58
63 public function withValue($value)
64 {
65 if ($value === null) {
66 $clone = clone $this;
67 $clone->value = $value;
68 $clone->null_value_was_explicitly_set = true;
69 return $clone;
70 }
74 $clone = parent::withValue($value);
75 $clone->null_value_was_explicitly_set = false;
76 return $clone;
77 }
78
82 public function getValue()
83 {
84 if ($this->null_value_was_explicitly_set) {
85 return null;
86 }
87 return parent::getValue();
88 }
89
90
94 public function withInput(InputData $post_input)
95 {
96 if ($this->getName() === null) {
97 throw new \LogicException("Can only collect if input has a name.");
98 }
99
100 if (!$this->isDisabled()) {
101 $value = $post_input->getOr($this->getName(), null);
102 if ($value === null) {
103 $clone = $this->withValue(null);
104 // Ugly hack to prevent shortcutting behaviour of applyOperationsTo
105 $temp = $clone->is_required;
106 $clone->is_required = true;
107 $clone->content = $clone->applyOperationsTo(null);
108 $clone->is_required = $temp;
109 return $clone;
110 }
111 }
112 return parent::withInput($post_input);
113 }
114}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
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.
isDisabled()
Is this input disabled?
This describes a group of inputs.
Definition: Group.php:14
withValue($value)
Get an input like this with another value displayed on the client side.
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.