ILIAS  release_8 Revision v8.24
class.ilADTLocalizedTextFormBridge.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
6
12{
16 protected function isValidADT(ilADT $a_adt): bool
17 {
18 return $a_adt instanceof ilADTLocalizedText;
19 }
20
24 public function addToForm(): void
25 {
26 $active_languages = $this->getADT()->getCopyOfDefinition()->getActiveLanguages();
27
28 if (!count($active_languages)) {
29 $this->addElementToForm(
30 $this->getTitle(),
31 (string) $this->getElementId(),
32 (string) $this->getADT()->getText(),
33 false,
34 ''
35 );
36 return;
37 }
38 $is_translation = null;
39 foreach ($active_languages as $active_language) {
40 if (strcmp($active_language, $this->getADT()->getCopyOfDefinition()->getDefaultLanguage()) === 0) {
41 $is_translation = false;
42 } else {
43 $is_translation = true;
44 }
45
46 $languages = $this->getADT()->getTranslations();
47
48 $text = '';
49
50 if (array_key_exists($active_language, $languages)) {
51 $text = $languages[$active_language];
52 }
53
54 $this->addElementToForm(
55 $this->getTitle(),
56 $this->getElementId() . '_' . $active_language,
57 $text,
58 $is_translation,
59 $active_language
60 );
61 }
62 }
63
67 public function importFromPost(): void
68 {
69 if (!$this->getADT()->getCopyOfDefinition()->supportsTranslations()) {
70 parent::importFromPost();
71 return;
72 }
73 $active_languages = $this->getADT()->getCopyOfDefinition()->getActiveLanguages();
74 foreach ($active_languages as $language) {
75 $this->getADT()->setTranslation(
76 $language,
77 $this->getForm()->getInput($this->getElementId() . '_' . $language)
78 );
79 $this->getADT()->setText($this->getForm()->getInput($this->getElementId() . '_' . $language));
80 $input_item = $this->getForm()->getItemByPostVar($this->getElementId() . '_' . $language);
81 $input_item->setValue((string) $this->getADT()->getTranslations()[$language]);
82 }
83 }
84}
Class ilADTLocalizedText.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addElementToForm(string $title, string $element_id, string $value, bool $is_translation=false, string $language='')
ADT base class.
Definition: class.ilADT.php:12