ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Text.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\UI\Component as C;
26 use Closure;
27 use Generator;
28 
32 class 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 
90  protected function getConstraintForRequirement(): ?Constraint
91  {
92  if ($this->requirement_constraint !== null) {
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 }
This implements commonalities between inputs.
Definition: Input.php:42
Interface Observer Contains several chained tasks and infos about them.
A constraint encodes some resrtictions on values.
Definition: Constraint.php:31
withAdditionalTransformation(Transformation $trafo)
Apply a transformation to the current or future content.
Definition: Input.php:145
This implements the text input.
Definition: Text.php:32
Factory for Date Formats.
Definition: Factory.php:26
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ilPlugin $plugin)
This describes inputs that can be used in forms.
Definition: FormInput.php:32
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, string $label, ?string $byline)
Definition: Text.php:40