ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
Group.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 use ILIAS\UI\Component as C;
30 use ilLanguage;
32 use Closure;
34 use Generator;
36 
41 {
42  use GroupInternals;
43 
47  public function __construct(
48  DataFactory $data_factory,
50  protected ilLanguage $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 
97  protected function getConstraintForRequirement(): ?Constraint
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(): \ilLanguage
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 }
This implements commonalities between inputs.
Definition: Input.php:42
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
getContent()
Get the current content of the input.
Definition: Group.php:129
Class ChatMainBarProvider .
setInputs(array $inputs)
This setter should be used instead of accessing $this->inputs directly.
Definition: Group.php:160
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:14
A constraint encodes some resrtictions on values.
Definition: Constraint.php:31
nameInputs(NameSource $source, string $parent_name)
Definition: Group.php:113
withOnUpdate(Signal $signal)
Trigger a signal of another component on update.
Definition: Group.php:87
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
_isClientSideValueOk($value)
ATTENTION: This is not the same as.
Definition: Group.php:128
__construct(VocabulariesInterface $vocabularies)
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event, &#39;$id&#39;, string_value);initially "onload" andon every input change. It must pass a readable string representation of its value in parameter &#39;string_value&#39;.
Definition: Group.php:105
$lng
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, protected ilLanguage $lng, array $inputs, string $label, ?string $byline=null)
Definition: Group.php:47
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:16
withNameFrom(NameSource $source, ?string $parent_name=null)
withDisabled(bool $is_disabled)
Get an input like this, but set it to a disabled state.
Definition: Group.php:60
ilErrorHandling $error
Definition: class.ilias.php:55
withNameFrom(NameSource $source)
Get an input like this one, with a different name.
This describes inputs that can be used in forms.
Definition: FormInput.php:31
Describes a source for input names.
Definition: NameSource.php:26
Refinery Factory $refinery