ILIAS  trunk Revision v12.0_alpha-1541-g23eaa5e013d
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 return;
173 }
174
175 $this->translations = $this->translations->withLanguage(
176 new Language(
177 $data['lang'],
178 $this->object->getTitle(),
179 $this->object->getDescription(),
180 true,
181 true
182 )
183 );
184
185 $this->object->getObjectProperties()->storePropertyTranslations(
186 $this->translations
187 );
188 $this->listTranslations();
189 }
static http()
Fetches the global http state from ILIAS.

References $data, 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 202 of file class.TranslationGUI.php.

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

◆ addContentTranslationToolbarActionAndRetrieveModal()

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

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

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

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 298 of file class.TranslationGUI.php.

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

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ deactivateContentTranslation()

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

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

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

References 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 286 of file class.TranslationGUI.php.

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

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getAddLanguageModal()

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

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

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

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 327 of file class.TranslationGUI.php.

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

References $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 277 of file class.TranslationGUI.php.

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

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getMasterLangSelectionInput()

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

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

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

References $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: