ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTTextFormBridge.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 protected bool $multi = false;
24 protected ?int $multi_rows;
25 protected ?int $multi_cols;
26
27 public function __construct(ilADT $a_adt)
28 {
29 parent::__construct($a_adt);
30 $this->lng->loadLanguageModule('meta');
31 }
32
33 public function setMulti(bool $a_value, ?int $a_cols = null, ?int $a_rows = null): void
34 {
35 $this->multi = $a_value;
36 $this->multi_rows = ($a_rows === null) ? null : $a_rows;
37 $this->multi_cols = ($a_cols === null) ? null : $a_cols;
38 }
39
40 public function isMulti(): bool
41 {
42 return $this->multi;
43 }
44
45 protected function isValidADT(ilADT $a_adt): bool
46 {
47 return ($a_adt instanceof ilADTText);
48 }
49
50 protected function addElementToForm(
51 string $title,
52 string $element_id,
53 string $value,
54 bool $is_translation = false,
55 string $language = ''
56 ): void {
57 $def = $this->getADT()->getCopyOfDefinition();
58
59 if (!$this->isMulti()) {
60 $text = new ilTextInputGUI($title, $element_id);
61
62 if ($def->getMaxLength()) {
63 $max = $def->getMaxLength();
64 $size = $text->getSize();
65
66 $text->setMaxLength($max);
67
68 if ($size && $max < $size) {
69 $text->setSize($max);
70 }
71 }
72 } else {
73 $text = new ilTextAreaInputGUI($title, $element_id);
74 if ($this->multi_rows) {
75 $text->setRows($this->multi_rows);
76 }
77 if ($this->multi_cols) {
78 $text->setCols($this->multi_cols);
79 }
80
81 if ($def->getMaxLength()) {
82 $max = $def->getMaxLength();
83 $text->setMaxNumOfChars($max);
84 }
85 }
86 $this->addBasicFieldProperties($text, $def);
87
88 if ($is_translation) {
89 $text->setInfo($this->lng->txt('md_adv_int_translation_info') . ' ' . $this->lng->txt('meta_l_' . $language));
90 $text->setRequired(false);
91 }
92 $text->setValue($value);
93 $this->addToParentElement($text);
94 }
95
96 public function addToForm(): void
97 {
98 $this->addElementToForm(
99 (string) $this->getTitle(),
100 (string) $this->getElementId(),
101 (string) $this->getADT()->getText()
102 );
103 }
104
105 public function importFromPost(): void
106 {
107 // ilPropertyFormGUI::checkInput() is pre-requisite
108 $this->getADT()->setText($this->getForm()->getInput($this->getElementId()));
109 $field = $this->getForm()->getItemByPostVar($this->getElementId());
110 $field->setValue($this->getADT()->getText());
111 }
112}
ADT form bridge base class.
addBasicFieldProperties(ilFormPropertyGUI $a_field, ilADTDefinition $a_def)
Helper method to handle generic properties like setRequired(), setInfo()
addToParentElement(ilFormPropertyGUI $a_field)
addToForm()
Add ADT-specific fields to form.
addElementToForm(string $title, string $element_id, string $value, bool $is_translation=false, string $language='')
setMulti(bool $a_value, ?int $a_cols=null, ?int $a_rows=null)
importFromPost()
Import values from form request POST data.
ADT base class.
Definition: class.ilADT.php:26
This class represents a text area property in a property form.
This class represents a text property in a property form.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc