ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
VocabValueConditionFactory.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 
33 {
36 
37  public function __construct(
42  VocabulariesInterface $vocabularies,
43  PathFactory $path_factory
44  ) {
45  parent::__construct($ui_factory, $presenter, $constraint_dictionary, $types);
46  $this->vocabularies = $vocabularies;
47  $this->path_factory = $path_factory;
48  }
49 
50  protected function conditionInput(
51  ElementInterface $element,
52  ElementInterface $context_element,
53  ElementInterface ...$conditional_elements
54  ): FormInput {
55  $groups = [];
56  foreach ($this->vocabularies->vocabulariesForElement($element) as $vocab) {
57  foreach ($vocab->values() as $value) {
58  $inputs = [];
59  foreach ($conditional_elements as $conditional_element) {
60  $input = $this->getInputInCondition(
61  $conditional_element,
62  $context_element,
63  $value
64  );
65  $path_string = $this->path_factory->toElement($conditional_element, true)
66  ->toString();
67  $inputs[$path_string] = $this->ui_factory->group(
68  [$input]
69  );
70  }
71  if (!isset($default_value)) {
72  $default_value = $value;
73  }
74  $groups[$value] = $this->ui_factory->group(
75  $inputs,
76  $this->presenter->data()->vocabularyValue($value)
77  );
78  }
79  }
80  $input = $this->ui_factory->switchableGroup(
81  $groups,
82  'placeholder'
83  );
84  if (isset($default_value)) {
85  return $input->withValue($default_value);
86  }
87  return $input;
88  }
89 }
This is what a factory for input fields looks like.
Definition: Factory.php:28
getInputInCondition(ElementInterface $element, ElementInterface $context_element, string $condition_value)
__construct(VocabulariesInterface $vocabularies)
$vocab
__construct(UIFactory $ui_factory, PresenterInterface $presenter, ConstraintDictionary $constraint_dictionary, FactoryWithoutConditionTypesService $types, VocabulariesInterface $vocabularies, PathFactory $path_factory)
conditionInput(ElementInterface $element, ElementInterface $context_element, ElementInterface ... $conditional_elements)
This describes inputs that can be used in forms.
Definition: FormInput.php:31
vocabularies(ElementInterface $element, bool $ignore_marker)