ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTLocalizedTextFormBridge.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
30 protected function isValidADT(ilADT $a_adt): bool
31 {
32 return $a_adt instanceof ilADTLocalizedText;
33 }
34
38 public function addToForm(): void
39 {
40 $active_languages = $this->getADT()->getCopyOfDefinition()->getActiveLanguages();
41 $multilingual_value_support = $this->getADT()->getCopyOfDefinition()->getMultilingualValueSupport();
42
43 if (
44 !count($active_languages) ||
45 !$multilingual_value_support
46 ) {
47
48 $languages = $this->getADT()->getTranslations();
49 $text = $languages[$this->getADT()->getCopyOfDefinition()->getDefaultLanguage()] ?? '';
50 $this->addElementToForm(
51 $this->getTitle(),
52 $this->getElementId() . '_' . $this->getADT()->getCopyOfDefinition()->getDefaultLanguage(),
53 $text,
54 false,
55 ''
56 );
57 return;
58 }
59 $is_translation = null;
60 foreach ($active_languages as $active_language) {
61 if (strcmp($active_language, $this->getADT()->getCopyOfDefinition()->getDefaultLanguage()) === 0) {
62 $is_translation = false;
63 } else {
64 $is_translation = true;
65 }
66
67 $languages = $this->getADT()->getTranslations();
68
69 $text = '';
70
71 if (array_key_exists($active_language, $languages)) {
72 $text = $languages[$active_language];
73 }
74
75 $this->addElementToForm(
76 $this->getTitle(),
77 $this->getElementId() . '_' . $active_language,
78 $text,
79 $is_translation,
80 $active_language
81 );
82 }
83 }
84
88 public function importFromPost(): void
89 {
90 $multilingual_value_support = $this->getADT()->getCopyOfDefinition()->getMultilingualValueSupport();
91 if (
92 !$this->getADT()->getCopyOfDefinition()->supportsTranslations() ||
93 !$multilingual_value_support
94 ) {
95 $language = $this->getADT()->getCopyOfDefinition()->getDefaultLanguage();
96 $this->getADT()->setTranslation(
97 $language,
98 $this->getForm()->getInput($this->getElementId() . '_' . $language)
99 );
100 $this->getADT()->setText($this->getForm()->getInput($this->getElementId() . '_' . $language));
101 $input_item = $this->getForm()->getItemByPostVar($this->getElementId() . '_' . $language);
102 $input_item->setValue($this->getADT()->getTextForLanguage($language));
103 return;
104 }
105 $active_languages = $this->getADT()->getCopyOfDefinition()->getActiveLanguages();
106 foreach ($active_languages as $language) {
107 $this->getADT()->setTranslation(
108 $language,
109 $this->getForm()->getInput($this->getElementId() . '_' . $language)
110 );
111 $this->getADT()->setText($this->getForm()->getInput($this->getElementId() . '_' . $language));
112 $input_item = $this->getForm()->getItemByPostVar($this->getElementId() . '_' . $language);
113 $input_item->setValue((string) $this->getADT()->getTranslations()[$language]);
114 }
115 }
116}
Class ilADTLocalizedText.
addElementToForm(string $title, string $element_id, string $value, bool $is_translation=false, string $language='')
ADT base class.
Definition: class.ilADT.php:26