ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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;
38 
43 {
44  use GroupInternals;
45  protected ilLanguage $lng;
46 
50  public function __construct(
51  DataFactory $data_factory,
53  ilLanguage $lng,
54  array $inputs,
55  string $label,
56  ?string $byline = null
57  ) {
58  parent::__construct($data_factory, $refinery, $label, $byline);
59  $this->checkInputListElements('inputs', $inputs, [C\Input\Container\Form\FormInput::class]);
60  $this->setInputs($inputs);
61  $this->lng = $lng;
62  }
63 
64  public function withDisabled(bool $is_disabled): LegacyInputInterface
65  {
66  $clone = parent::withDisabled($is_disabled);
67  $clone->setInputs(array_map(fn ($i) => $i->withDisabled($is_disabled), $this->getInputs()));
68  return $clone;
69  }
70 
71  public function withRequired(bool $is_required, ?Constraint $requirement_constraint = null): LegacyInputInterface
72  {
73  $clone = parent::withRequired($is_required, $requirement_constraint);
74  $clone->setInputs(array_map(fn ($i) => $i->withRequired($is_required, $requirement_constraint), $this->getInputs()));
75  return $clone;
76  }
77 
78  public function isRequired(): bool
79  {
80  if ($this->is_required) {
81  return true;
82  }
83  foreach ($this->getInputs() as $input) {
84  if ($input->isRequired()) {
85  return true;
86  }
87  }
88  return false;
89  }
90 
91  public function withOnUpdate(Signal $signal)
92  {
93  $clone = parent::withOnUpdate($signal);
94  $clone->setInputs(array_map(fn ($i) => $i->withOnUpdate($signal), $this->getInputs()));
95  return $clone;
96  }
97 
102  {
103  return null;
104  }
105 
109  public function getUpdateOnLoadCode(): Closure
110  {
111  return function () {
112  /*
113  * Currently, there is no use case for Group here. The single Inputs
114  * within the Group are responsible for handling getUpdateOnLoadCode().
115  */
116  };
117  }
118 
122  public function withNameFrom(NameSource $source, ?string $parent_name = null): LegacyInputInterface
123  {
125  $clone = parent::withNameFrom($source, $parent_name);
126  $clone->setInputs($this->nameInputs($source, $clone->getName()));
127  return $clone;
128  }
129 
133  public function getContent(): Result
134  {
135  if (empty($this->getInputs())) {
136  return new Ok([]);
137  }
138  return parent::getContent();
139  }
140 
144  protected function setError(string $error): void
145  {
146  $this->error = $error;
147  }
148 
149  protected function getLanguage(): \ilLanguage
150  {
151  return $this->lng;
152  }
153 
154  protected function getDataFactory(): DataFactory
155  {
156  return $this->data_factory;
157  }
158 
160  protected function isClientSideValueOk($value): bool
161  {
162  return $this->_isClientSideValueOk($value);
163  }
164 }
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:71
This implements the group input.
Definition: Group.php:42
getContent()
Get the current content of the input.
Definition: Group.php:133
Class ChatMainBarProvider .
setInputs(array $inputs)
This setter should be used instead of accessing $this->inputs directly.
Definition: Group.php:161
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:114
withOnUpdate(Signal $signal)
Trigger a signal of another component on update.
Definition: Group.php:91
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, ilLanguage $lng, array $inputs, string $label, ?string $byline=null)
Definition: Group.php:50
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:129
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:109
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)
__construct(Container $dic, ilPlugin $plugin)
withDisabled(bool $is_disabled)
Get an input like this, but set it to a disabled state.
Definition: Group.php:64
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
$source
Definition: metadata.php:93
$i
Definition: metadata.php:41
Refinery Factory $refinery