ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\ILIASObject\Properties\Translations\TranslationGUI Class Reference

GUI class for object translation handling. More...

+ Collaboration diagram for ILIAS\ILIASObject\Properties\Translations\TranslationGUI:

Public Member Functions

 __construct (private readonly \ilObject $object, private readonly \ilLanguage $lng, private readonly \ilAccess $access, private readonly \ilObjUser $user, private readonly \ilCtrl $ctrl, private readonly \ilGlobalTemplateInterface $tpl, private readonly UIFactory $ui_factory, private readonly UIRenderer $ui_renderer, private readonly HTTPService $http, private readonly Refinery $refinery, private readonly \ilToolbarGUI $toolbar)
 
 supportContentTranslation (bool $content_translation)
 
 forceContentTranslation ()
 Some objects like learning modules do not support to translate only the title and the description. More...
 
 executeCommand ()
 
 listTranslations (?RoundtripModal $lang_modal=null)
 
 addTranslation ()
 
 activateContentTranslation ()
 
 deactivateContentTranslation ()
 

Private Member Functions

 addAddLanguagesToolbarActionAndRetrieveModal (?RoundtripModal $modal=null)
 
 getAddLanguageModal ()
 
 addContentTranslationToolbarActionAndRetrieveModal ()
 
 getConfirmDeactivateMultilingualityModal (string $text_tag)
 
 getActivateMultilingualityModal ()
 
 buildLangSelectionInput ()
 
 getMasterLangSelectionInput ()
 
 getArrayWithAddableLanguages ()
 

Private Attributes

const CMD_LIST_TRANSLATIONS = 'listTranslations'
 
const CMD_ADD_TRANSLATION = 'addTranslation'
 
const CMD_DEACTIVATE_CONTENT_MULTILANG = 'deactivateContentTranslation'
 
const CMD_SAVE_CONTENT_TRANSLATION_ACTIVATION = 'activateContentTranslation'
 
Translations $translations
 
bool $force_content_translation = false
 
bool $supports_content_translation = true
 

Detailed Description

GUI class for object translation handling.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e

Definition at line 38 of file class.TranslationGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::__construct ( private readonly \ilObject  $object,
private readonly \ilLanguage  $lng,
private readonly \ilAccess  $access,
private readonly \ilObjUser  $user,
private readonly \ilCtrl  $ctrl,
private readonly \ilGlobalTemplateInterface  $tpl,
private readonly UIFactory  $ui_factory,
private readonly UIRenderer  $ui_renderer,
private readonly HTTPService  $http,
private readonly Refinery  $refinery,
private readonly \ilToolbarGUI  $toolbar 
)

Definition at line 50 of file class.TranslationGUI.php.

62 {
63 $this->translations = $this->object->getObjectProperties()->getPropertyTranslations();
64 }

Member Function Documentation

◆ activateContentTranslation()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::activateContentTranslation ( )

Definition at line 165 of file class.TranslationGUI.php.

165 : void
166 {
168 ->withRequest($this->http->request())
169 ->getData();
170
171 if ($data === null) {
172 $this->listTranslations();
173 return;
174 }
175
176 $this->translations = $this->translations->withLanguage(
177 new Language(
178 $data['lang'],
179 $this->object->getTitle(),
180 $this->object->getDescription(),
181 true,
182 true
183 )
184 );
185
186 $this->object->getObjectProperties()->storePropertyTranslations(
187 $this->translations
188 );
189 $this->ctrl->redirectByClass(self::class);
190 }
static http()
Fetches the global http state from ILIAS.
$data
Definition: storeScorm.php:45

References $data, ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), and ILIAS\Repository\object().

+ Here is the call graph for this function:

◆ addAddLanguagesToolbarActionAndRetrieveModal()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::addAddLanguagesToolbarActionAndRetrieveModal ( ?RoundtripModal  $modal = null)
private

Definition at line 203 of file class.TranslationGUI.php.

205 : RoundtripModal {
206 $modal ??= $this->getAddLanguageModal();
207 $this->toolbar->addComponent(
208 $this->ui_factory->button()->standard(
209 $this->lng->txt('obj_add_language'),
210 $modal->getShowSignal()
211 )
212 );
213
214 return $modal;
215 }

◆ addContentTranslationToolbarActionAndRetrieveModal()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::addContentTranslationToolbarActionAndRetrieveModal ( )
private

Definition at line 244 of file class.TranslationGUI.php.

244 : Modal
245 {
246 $lang_var_postfix = '_multilang';
247 $deactivation_modal_text_tag = 'obj_deactivate_multilang_conf';
248 if (!$this->force_content_translation) {
249 $lang_var_postfix = '_content_lang';
250 $deactivation_modal_text_tag = 'obj_deactivate_content_transl_conf';
251 }
252
253 if (!$this->force_content_translation && !$this->translations->getContentTranslationActivated()) {
254 $this->tpl->setOnScreenMessage('info', $this->lng->txt('obj_multilang_title_descr_only'));
255 }
256
257 if (!$this->translations->getContentTranslationActivated()) {
258 $activate_modal = $this->getActivateMultilingualityModal();
259 $this->toolbar->addComponent(
260 $this->ui_factory->button()->standard(
261 $this->lng->txt('obj_activate' . $lang_var_postfix),
262 $activate_modal->getShowSignal()
263 )
264 );
265 return $activate_modal;
266 }
267
268 $deactivate_modal = $this->getConfirmDeactivateMultilingualityModal($deactivation_modal_text_tag);
269 $this->toolbar->addComponent(
270 $this->ui_factory->button()->standard(
271 $this->lng->txt('obj_deactivate' . $lang_var_postfix),
272 $deactivate_modal->getShowSignal()
273 )
274 );
275 return $deactivate_modal;
276 }

References ILIAS\Repository\lng(), and ILIAS\Repository\toolbar().

+ Here is the call graph for this function:

◆ addTranslation()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::addTranslation ( )

Definition at line 147 of file class.TranslationGUI.php.

147 : void
148 {
149 $modal = $this->getAddLanguageModal()
150 ->withRequest($this->http->request());
151 $data = $modal->getData();
152 if ($data === null) {
153 $this->listTranslations($modal->withOnLoad($modal->getShowSignal()));
154 return;
155 }
156
157 $this->translations = $this->translations->withLanguage($data[0]);
158 $this->object->getObjectProperties()->storePropertyTranslations(
159 $this->translations
160 );
161 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
162 $this->ctrl->redirectByClass($this->ctrl->getCurrentClassPath());
163 }

References $data, ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ buildLangSelectionInput()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::buildLangSelectionInput ( )
private

Definition at line 299 of file class.TranslationGUI.php.

299 : SelectInput
300 {
301 return $this->ui_factory->input()->field()->select(
302 $this->lng->txt('language'),
303 $this->getArrayWithAddableLanguages()
304 );
305 }

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ deactivateContentTranslation()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::deactivateContentTranslation ( )

Definition at line 192 of file class.TranslationGUI.php.

192 : void
193 {
194 $this->translations = $this->translations->withDeactivatedContentTranslation();
195 $this->object->getObjectProperties()->storePropertyTranslations(
196 $this->translations
197 );
198
199 $this->tpl->setOnScreenMessage('success', $this->lng->txt('obj_cont_transl_deactivated'), true);
200 $this->ctrl->redirectByClass(self::class);
201 }

References ILIAS\Repository\ctrl(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ executeCommand()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::executeCommand ( )

Definition at line 83 of file class.TranslationGUI.php.

83 : void
84 {
85 $commands = [
90 ];
91
92 $this->ctrl->getNextClass($this);
93 $cmd = $this->ctrl->getCmd(self::CMD_LIST_TRANSLATIONS);
94 if (!$this->access->checkAccess('write', '', $this->object->getRefId())) {
95 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_permission'));
96 $this->ctrl->redirectByClass(get_class($this->object) . 'GUI');
97 }
98 if (in_array($cmd, $commands)) {
99 $this->$cmd();
100 }
101 }

References ILIAS\Repository\access(), ILIAS\ILIASObject\Properties\Translations\TranslationGUI\CMD_ADD_TRANSLATION, ILIAS\ILIASObject\Properties\Translations\TranslationGUI\CMD_DEACTIVATE_CONTENT_MULTILANG, ILIAS\ILIASObject\Properties\Translations\TranslationGUI\CMD_LIST_TRANSLATIONS, ILIAS\ILIASObject\Properties\Translations\TranslationGUI\CMD_SAVE_CONTENT_TRANSLATION_ACTIVATION, ILIAS\Repository\ctrl(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ forceContentTranslation()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::forceContentTranslation ( )

Some objects like learning modules do not support to translate only the title and the description.

If they acticate multilinguasm, they translate always title, description AND content. They have to call setTitleDescrOnlyMode(false) to indicate this. Other contexts, e.g. categories allow to only translate title and description and activate the content multilinguasm separately.

Definition at line 78 of file class.TranslationGUI.php.

78 : void
79 {
80 $this->force_content_translation = true;
81 }

◆ getActivateMultilingualityModal()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::getActivateMultilingualityModal ( )
private

Definition at line 287 of file class.TranslationGUI.php.

287 : RoundtripModal
288 {
289 return $this->ui_factory->modal()->roundtrip(
290 $this->lng->txt('confirm'),
291 $this->ui_factory->legacy()->content($this->lng->txt('obj_select_base_lang')),
292 [
293 'lang' => $this->getMasterLangSelectionInput()
294 ],
295 $this->ctrl->getFormActionByClass(self::class, self::CMD_SAVE_CONTENT_TRANSLATION_ACTIVATION)
296 );
297 }

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getAddLanguageModal()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::getAddLanguageModal ( )
private

Definition at line 217 of file class.TranslationGUI.php.

217 : RoundtripModal
218 {
219 $ff = $this->ui_factory->input()->field();
220 return $this->ui_factory->modal()->roundtrip(
221 $this->lng->txt('obj_add_language'),
222 null,
223 [
224 $ff->group([
225 'language' => $this->buildLangSelectionInput()
226 ->withRequired(true),
227 'title' => $ff->text($this->lng->txt('title'))
228 ->withRequired(true),
229 'description' => $ff->textarea($this->lng->txt('description'))
230 ])->withAdditionalTransformation(
231 $this->refinery->custom()->transformation(
232 static fn(array $vs): Language => new Language(
233 $vs['language'],
234 $vs['title'],
235 $vs['description']
236 )
237 )
238 )
239 ],
240 $this->ctrl->getFormActionByClass(self::class, self::CMD_ADD_TRANSLATION)
241 );
242 }

References ILIAS\Repository\ctrl(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getArrayWithAddableLanguages()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::getArrayWithAddableLanguages ( )
private

Definition at line 328 of file class.TranslationGUI.php.

328 : array
329 {
330 $enabled_langs = $this->translations->getLanguages();
331 return array_reduce(
332 $this->lng->getInstalledLanguages(),
333 function (array $c, string $v) use ($enabled_langs): array {
334 if (!array_key_exists($v, $enabled_langs)) {
335 $c[$v] = $this->lng->txt("meta_l_{$v}");
336 }
337 return $c;
338 },
339 []
340 );
341 }

References Vendor\Package\$c, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getConfirmDeactivateMultilingualityModal()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::getConfirmDeactivateMultilingualityModal ( string  $text_tag)
private

Definition at line 278 of file class.TranslationGUI.php.

278 : Modal
279 {
280 return $this->ui_factory->modal()->interruptive(
281 $this->lng->txt('confirm'),
282 $this->lng->txt($text_tag),
283 $this->ctrl->getFormActionByClass(self::class, self::CMD_DEACTIVATE_CONTENT_MULTILANG)
284 )->withActionButtonLabel($this->lng->txt('confirm'));
285 }

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getMasterLangSelectionInput()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::getMasterLangSelectionInput ( )
private

Definition at line 307 of file class.TranslationGUI.php.

307 : Input
308 {
309 $options = array_reduce(
310 $this->lng->getInstalledLanguages(),
311 function (array $c, string $v): array {
312 $c[$v] = $this->lng->txt("meta_l_{$v}");
313 return $c;
314 },
315 []
316 );
317
318 return $this->ui_factory->input()->field()->select(
319 $this->lng->txt('obj_base_lang'),
321 )->withAdditionalTransformation(
322 $this->refinery->custom()->transformation(
323 fn($v) => in_array($v, array_keys($options)) ? $v : $this->lng->getDefaultLanguage()
324 )
325 )->withValue($this->user->getLanguage());
326 }

References Vendor\Package\$c, ILIAS\UI\Implementation\Component\Input\Field\$options, ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ listTranslations()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::listTranslations ( ?RoundtripModal  $lang_modal = null)

Definition at line 103 of file class.TranslationGUI.php.

105 : void {
106 $this->lng->loadLanguageModule($this->object->getType());
107
108 $table = new TranslationsTable(
109 $this->ui_factory,
110 $this->ui_renderer,
111 $this->lng,
112 $this->refinery,
113 $this->tpl,
114 $this->http,
115 $this->ctrl,
116 $this->translations,
117 $this->object->getObjectProperties(),
118 (new DataFactory())->uri(
119 ILIAS_HTTP_PATH . '/' . $this->ctrl->getFormActionByClass(
120 self::class,
121 self::CMD_LIST_TRANSLATIONS
122 )
123 )
124 );
125 $table->runAction();
126 $content = [
127 'table' => $table->getTable()
128 ];
129
130 if ($this->translations->migrationMissing()) {
131 $this->tpl->setOnScreenMessage('info', $this->lng->txt('missing_migration'));
132 $this->tpl->setContent($this->ui_renderer->render($content));
133 return;
134 }
135
136 if ($this->getArrayWithAddableLanguages() !== []) {
137 $content['lang_modal'] = $this->addAddLanguagesToolbarActionAndRetrieveModal($lang_modal);
138 }
139
140 if ($this->supports_content_translation) {
141 $content['content_trans_modal'] = $this->addContentTranslationToolbarActionAndRetrieveModal();
142 }
143
144 $this->tpl->setContent($this->ui_renderer->render($content));
145 }

◆ supportContentTranslation()

ILIAS\ILIASObject\Properties\Translations\TranslationGUI::supportContentTranslation ( bool  $content_translation)

Definition at line 66 of file class.TranslationGUI.php.

66 : void
67 {
68 $this->supports_content_translation = $content_translation;
69 }

Field Documentation

◆ $force_content_translation

bool ILIAS\ILIASObject\Properties\Translations\TranslationGUI::$force_content_translation = false
private

Definition at line 47 of file class.TranslationGUI.php.

◆ $supports_content_translation

bool ILIAS\ILIASObject\Properties\Translations\TranslationGUI::$supports_content_translation = true
private

Definition at line 48 of file class.TranslationGUI.php.

◆ $translations

Translations ILIAS\ILIASObject\Properties\Translations\TranslationGUI::$translations
private

Definition at line 45 of file class.TranslationGUI.php.

◆ CMD_ADD_TRANSLATION

const ILIAS\ILIASObject\Properties\Translations\TranslationGUI::CMD_ADD_TRANSLATION = 'addTranslation'
private

◆ CMD_DEACTIVATE_CONTENT_MULTILANG

const ILIAS\ILIASObject\Properties\Translations\TranslationGUI::CMD_DEACTIVATE_CONTENT_MULTILANG = 'deactivateContentTranslation'
private

◆ CMD_LIST_TRANSLATIONS

const ILIAS\ILIASObject\Properties\Translations\TranslationGUI::CMD_LIST_TRANSLATIONS = 'listTranslations'
private

◆ CMD_SAVE_CONTENT_TRANSLATION_ACTIVATION

const ILIAS\ILIASObject\Properties\Translations\TranslationGUI::CMD_SAVE_CONTENT_TRANSLATION_ACTIVATION = 'activateContentTranslation'
private

The documentation for this class was generated from the following file: