ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Text.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\Data\Factory as DataFactory;
26use Closure;
27use Generator;
28
32class Text extends FormInput implements C\Input\Field\Text
33{
34 private ?int $max_length = null;
35 private bool $strip_tags_from_input = true;
36
40 public function __construct(
41 DataFactory $data_factory,
43 string $label,
44 ?string $byline
45 ) {
46 parent::__construct($data_factory, $refinery, $label, $byline);
47 }
48
52 public function withMaxLength(int $max_length): C\Input\Field\Text
53 {
54 $clone = $this->withAdditionalTransformation(
55 $this->refinery->string()->hasMaxLength($max_length)
56 );
57 $clone->max_length = $max_length;
58
59 return $clone;
60 }
61
65 public function getMaxLength(): ?int
66 {
67 return $this->max_length;
68 }
69
73 protected function isClientSideValueOk($value): bool
74 {
75 if (!is_string($value)) {
76 return false;
77 }
78
79 if ($this->max_length !== null &&
80 strlen($value) > $this->max_length) {
81 return false;
82 }
83
84 return true;
85 }
86
91 {
92 if ($this->requirement_constraint !== null) {
93 return $this->requirement_constraint;
94 }
95
96 return $this->refinery->string()->hasMinLength(1);
97 }
98
102 public function getUpdateOnLoadCode(): Closure
103 {
104 return fn($id) => "$('#$id').on('input', function(event) {
105 il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());
106 });
107 il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());";
108 }
109
113 public function isComplex(): bool
114 {
115 return false;
116 }
117
121 public function getOperations(): Generator
122 {
123 if ($this->strip_tags_from_input) {
124 yield $this->refinery->custom()->transformation(fn($v) => strip_tags($v));
125 }
126 yield from parent::getOperations();
127 }
128
132 public function withoutStripTags(): Text
133 {
134 $clone = clone $this;
135 $clone->strip_tags_from_input = false;
136 return $clone;
137 }
138}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Factory for Date Formats.
Definition: Factory.php:27
Builds data types.
Definition: Factory.php:36
This implements the text input.
Definition: Text.php:33
withMaxLength(int $max_length)
@inheritDoc
Definition: Text.php:52
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event,...
Definition: Text.php:102
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, string $label, ?string $byline)
Definition: Text.php:40
This implements commonalities between inputs.
Definition: Input.php:43
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
This describes inputs that can be used in forms.
Definition: FormInput.php:33
withAdditionalTransformation(Transformation $trafo)
Apply a transformation to the content of the input.
__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
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.