19declare(strict_types=1);
55 private readonly \
ilCtrl $ctrl,
57 private readonly UIFactory $ui_factory,
58 private readonly UIRenderer $ui_renderer,
59 private readonly HTTPService
$http,
63 $this->translations = $this->
object->getObjectProperties()->getPropertyTranslations();
68 $this->supports_content_translation = $content_translation;
80 $this->force_content_translation =
true;
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');
98 if (in_array($cmd, $commands)) {
104 ?RoundtripModal $lang_modal =
null
106 $this->
lng->loadLanguageModule($this->
object->getType());
117 $this->
object->getObjectProperties(),
118 (
new DataFactory())->uri(
119 ILIAS_HTTP_PATH .
'/' . $this->
ctrl->getFormActionByClass(
121 self::CMD_LIST_TRANSLATIONS
127 'table' => $table->getTable()
130 if ($this->translations->migrationMissing()) {
131 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'missing_migration'));
132 $this->tpl->setContent($this->ui_renderer->render($content));
140 if ($this->supports_content_translation) {
144 $this->tpl->setContent($this->ui_renderer->render($content));
149 $modal = $this->getAddLanguageModal()
150 ->withRequest($this->
http->request());
151 $data = $modal->getData();
152 if (
$data ===
null) {
153 $this->listTranslations($modal->withOnLoad($modal->getShowSignal()));
157 $this->translations = $this->translations->withLanguage(
$data[0]);
158 $this->
object->getObjectProperties()->storePropertyTranslations(
161 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
162 $this->
ctrl->redirectByClass($this->
ctrl->getCurrentClassPath());
167 $data = $this->getActivateMultilingualityModal()
168 ->withRequest($this->
http->request())
171 if (
$data ===
null) {
175 $this->translations = $this->translations->withLanguage(
178 $this->
object->getTitle(),
179 $this->object->getDescription(),
185 $this->
object->getObjectProperties()->storePropertyTranslations(
188 $this->listTranslations();
193 $this->translations = $this->translations->withDeactivatedContentTranslation();
194 $this->
object->getObjectProperties()->storePropertyTranslations(
198 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'obj_cont_transl_deactivated'),
true);
199 $this->listTranslations();
203 ?RoundtripModal $modal =
null
205 $modal ??= $this->getAddLanguageModal();
207 $this->ui_factory->button()->standard(
208 $this->lng->txt(
'obj_add_language'),
209 $modal->getShowSignal()
218 $ff = $this->ui_factory->input()->field();
219 return $this->ui_factory->modal()->roundtrip(
220 $this->
lng->txt(
'obj_add_language'),
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(
239 $this->
ctrl->getFormActionByClass(self::class, self::CMD_ADD_TRANSLATION)
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';
252 if (!$this->force_content_translation && !$this->translations->getContentTranslationActivated()) {
253 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'obj_multilang_title_descr_only'));
256 if (!$this->translations->getContentTranslationActivated()) {
257 $activate_modal = $this->getActivateMultilingualityModal();
259 $this->ui_factory->button()->standard(
260 $this->lng->txt(
'obj_activate' . $lang_var_postfix),
261 $activate_modal->getShowSignal()
264 return $activate_modal;
267 $deactivate_modal = $this->getConfirmDeactivateMultilingualityModal($deactivation_modal_text_tag);
269 $this->ui_factory->button()->standard(
270 $this->lng->txt(
'obj_deactivate' . $lang_var_postfix),
271 $deactivate_modal->getShowSignal()
274 return $deactivate_modal;
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'));
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')),
292 'lang' => $this->getMasterLangSelectionInput()
294 $this->ctrl->getFormActionByClass(self::class, self::CMD_SAVE_CONTENT_TRANSLATION_ACTIVATION)
300 return $this->ui_factory->input()->field()->select(
301 $this->
lng->txt(
'language'),
302 $this->getArrayWithAddableLanguages()
309 $this->
lng->getInstalledLanguages(),
310 function (array
$c,
string $v): array {
311 $c[$v] = $this->
lng->txt(
"meta_l_{$v}");
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()
324 )->withValue($this->
user->getLanguage());
329 $enabled_langs = $this->translations->getLanguages();
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}");
Builds a Color from either hex- or rgb values.
GUI class for object translation handling.
const CMD_SAVE_CONTENT_TRANSLATION_ACTIVATION
forceContentTranslation()
Some objects like learning modules do not support to translate only the title and the description.
getArrayWithAddableLanguages()
addAddLanguagesToolbarActionAndRetrieveModal(?RoundtripModal $modal=null)
getMasterLangSelectionInput()
listTranslations(?RoundtripModal $lang_modal=null)
Translations $translations
supportContentTranslation(bool $content_translation)
bool $supports_content_translation
const CMD_DEACTIVATE_CONTENT_MULTILANG
getConfirmDeactivateMultilingualityModal(string $text_tag)
bool $force_content_translation
addContentTranslationToolbarActionAndRetrieveModal()
const CMD_LIST_TRANSLATIONS
__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)
buildLangSelectionInput()
deactivateContentTranslation()
getActivateMultilingualityModal()
activateContentTranslation()
const CMD_ADD_TRANSLATION
Class handles translation mode for an object.
Class ilAccessHandler Checks access for ILIAS objects.
Class ilCtrl provides processing control methods.
Class ilObject Basic functions for all objects.
This describes commonalities between the different modals.
An entity that renders components to a string output.
static http()
Fetches the global http state from ILIAS.