ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
InputHelper.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30
31trait InputHelper
32{
33 protected function getInputLabelFromElement(
34 PresenterInterface $presenter,
35 ElementInterface $element,
36 ElementInterface $context_element
37 ): string {
38 return $presenter->elements()->nameWithParents(
39 $element,
40 $context_element,
41 false
42 );
43 }
44
45 protected function addValueFromElement(
46 ElementInterface $element,
47 FormInput $input
48 ): FormInput {
49 if ($element->getData()->type() === Type::NULL) {
50 return $input;
51 }
52 return $input->withValue($element->getData()->value());
53 }
54
55 protected function addConstraintsFromElement(
56 ConstraintDictionary $constraint_dictionary,
57 ElementInterface $element,
58 FormInput $input,
59 bool $skip_value = false
60 ): FormInput {
61 foreach ($constraint_dictionary->tagsForElement($element) as $tag) {
62 $input = $this->addConstraintFromTag($input, $tag, $skip_value);
63 }
64 return $input;
65 }
66
67 private function addConstraintFromTag(
68 FormInput $input,
69 ConstraintTag $tag,
70 bool $skip_value
71 ): FormInput {
72 switch ($tag->restriction()) {
73 case Restriction::PRESET_VALUE:
74 if ($skip_value) {
75 return $input;
76 }
77 return $input->withValue($tag->value());
78
79 case Restriction::NOT_DELETABLE:
80 return $input->withRequired(true);
81
83 return $input->withDisabled(true);
84 }
85 return $input;
86 }
87
88 protected function getPresetValueFromConstraints(
89 ConstraintDictionary $constraint_dictionary,
90 ElementInterface $element
91 ): ?string {
92 $preset_value = null;
93 foreach ($constraint_dictionary->tagsForElement($element) as $tag) {
94 if ($tag->restriction() !== Restriction::PRESET_VALUE) {
95 continue;
96 }
97 $preset_value = $tag->value();
98 }
99 return $preset_value;
100 }
101}
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes inputs that can be used in forms.
Definition: FormInput.php:33
if(!file_exists('../ilias.ini.php'))