ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Group.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28use ILIAS\UI\Implementation\Component\ComponentHelper;
29use ILIAS\Data\Factory as DataFactory;
32use Closure;
34use Generator;
36
41{
42 use GroupInternals;
43
47 public function __construct(
48 DataFactory $data_factory,
50 protected Language $lng,
51 array $inputs,
52 string $label,
53 ?string $byline = null
54 ) {
55 parent::__construct($data_factory, $refinery, $label, $byline);
56 $this->checkInputListElements('inputs', $inputs, [C\Input\Container\Form\FormInput::class]);
57 $this->setInputs($inputs);
58 }
59
60 public function withDisabled(bool $is_disabled): self
61 {
62 $clone = parent::withDisabled($is_disabled);
63 $clone->setInputs(array_map(fn($i) => $i->withDisabled($is_disabled), $this->getInputs()));
64 return $clone;
65 }
66
67 public function withRequired(bool $is_required, ?Constraint $requirement_constraint = null): self
68 {
69 $clone = parent::withRequired($is_required, $requirement_constraint);
70 $clone->setInputs(array_map(fn($i) => $i->withRequired($is_required, $requirement_constraint), $this->getInputs()));
71 return $clone;
72 }
73
74 public function isRequired(): bool
75 {
76 if ($this->is_required) {
77 return true;
78 }
79 foreach ($this->getInputs() as $input) {
80 if ($input->isRequired()) {
81 return true;
82 }
83 }
84 return false;
85 }
86
87 public function withOnUpdate(Signal $signal): self
88 {
89 $clone = parent::withOnUpdate($signal);
90 $clone->setInputs(array_map(fn($i) => $i->withOnUpdate($signal), $this->getInputs()));
91 return $clone;
92 }
93
98 {
99 return null;
100 }
101
105 public function getUpdateOnLoadCode(): Closure
106 {
107 return function () {
108 /*
109 * Currently, there is no use case for Group here. The single Inputs
110 * within the Group are responsible for handling getUpdateOnLoadCode().
111 */
112 };
113 }
114
118 public function withNameFrom(NameSource $source, ?string $parent_name = null): self
119 {
121 $clone = parent::withNameFrom($source, $parent_name);
122 $clone->setInputs($this->nameInputs($source, $clone->getName()));
123 return $clone;
124 }
125
129 public function getContent(): Result
130 {
131 if (empty($this->getInputs())) {
132 return new Ok([]);
133 }
134 return parent::getContent();
135 }
136
140 protected function setError(string $error): void
141 {
142 $this->error = $error;
143 }
144
145 protected function getLanguage(): Language
146 {
147 return $this->lng;
148 }
149
150 protected function getDataFactory(): DataFactory
151 {
152 return $this->data_factory;
153 }
154
156 protected function isClientSideValueOk($value): bool
157 {
158 return $this->_isClientSideValueOk($value);
159 }
160
161 protected function getSubComponents(): ?array
162 {
163 return $this->getInputs();
164 }
165}
Factory for Date Formats.
Definition: Factory.php:27
Builds data types.
Definition: Factory.php:36
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
This implements commonalities between all forms.
Definition: Form.php:34
This implements the group input.
Definition: Group.php:41
getContent()
Get the current content of the input.
Definition: Group.php:129
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event,...
Definition: Group.php:105
withDisabled(bool $is_disabled)
Get an input like this, but set it to a disabled state.
Definition: Group.php:60
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, protected Language $lng, array $inputs, string $label, ?string $byline=null)
Definition: Group.php:47
withOnUpdate(Signal $signal)
Trigger a signal of another component on update.
Definition: Group.php:87
withRequired(bool $is_required, ?Constraint $requirement_constraint=null)
Get an input like this, but set the field to be required (or not).
Definition: Group.php:67
This implements commonalities between inputs.
Definition: Input.php:43
ilErrorHandling $error
Definition: class.ilias.php:69
error(string $a_errmsg)
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:29
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
This describes inputs that can be used in forms.
Definition: FormInput.php:33
withNameFrom(NameSource $source)
Get an input like this one, with a different name.
Describes a source for input names.
Definition: NameSource.php:27
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
withNameFrom(NameSource $source, ?string $parent_name=null)
@inheritDoc
nameInputs(NameSource $source, string $parent_name)
Definition: Group.php:116
_isClientSideValueOk($value)
ATTENTION: This is not the same as.
Definition: Group.php:131
setInputs(array $inputs)
This setter should be used instead of accessing $this->inputs directly.
Definition: Group.php:163
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31