ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 164 of file class.TranslationGUI.php.

164 : void
165 {
167 ->withRequest($this->http->request())
168 ->getData();
169
170 if ($data === null) {
171 return;
172 }
173
174 $this->translations = $this->translations->withLanguage(
175 new Language(
176 $data['lang'],
177 $this->object->getTitle(),
178 $this->object->getDescription(),
179 true,
180 true
181 )
182 );
183
184 $this->object->getObjectProperties()->storePropertyTranslations(
185 $this->translations
186 );
187 $this->listTranslations();
188 }
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 201 of file class.TranslationGUI.php.

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

◆ addContentTranslationToolbarActionAndRetrieveModal()

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

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

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

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->ctrl->redirectByClass($this->ctrl->getCurrentClassPath());
162 }

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

+ Here is the call graph for this function:

◆ buildLangSelectionInput()

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

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

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

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ deactivateContentTranslation()

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

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

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

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

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

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getAddLanguageModal()

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

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

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

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

326 : array
327 {
328 $enabled_langs = $this->translations->getLanguages();
329 return array_reduce(
330 $this->lng->getInstalledLanguages(),
331 function (array $c, string $v) use ($enabled_langs): array {
332 if (!array_key_exists($v, $enabled_langs)) {
333 $c[$v] = $this->lng->txt("meta_l_{$v}");
334 }
335 return $c;
336 },
337 []
338 );
339 }
$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 276 of file class.TranslationGUI.php.

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

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getMasterLangSelectionInput()

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

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

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

References $c, ILIAS\Repository\lng(), ILIAS\Repository\refinery(), ILIAS\Repository\user(), and ILIAS\UI\Component\Input\Input\withAdditionalTransformation().

+ 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: