From c2b09a90fb258e3f2aa4135396590d0628bb2140 Mon Sep 17 00:00:00 2001 From: Thomas Hackl <hackl@data-quest.de> Date: Fri, 14 Jan 2022 13:59:11 +0100 Subject: [PATCH] check if the I18NString is an object or just a string (happens when only one content language is defined), re #154 --- .../AdvancedBasicDataWizardStep.php | 4 +- .../coursewizardsteps/BasicDataWizardStep.php | 38 +++++++++++-------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/lib/classes/coursewizardsteps/AdvancedBasicDataWizardStep.php b/lib/classes/coursewizardsteps/AdvancedBasicDataWizardStep.php index 1843084ded4..595c5fe5202 100644 --- a/lib/classes/coursewizardsteps/AdvancedBasicDataWizardStep.php +++ b/lib/classes/coursewizardsteps/AdvancedBasicDataWizardStep.php @@ -132,9 +132,9 @@ class AdvancedBasicDataWizardStep extends BasicDataWizardStep $values[__CLASS__] = array_merge($values[__CLASS__], [ 'subtitle' => $course->untertitel, - 'subtitle_i18n' => $course->untertitel->toArray(), + 'subtitle_i18n' => is_object($course->untertitel) ? $course->untertitel->toArray() : $course->untertitel, 'kind' => $course->art, - 'kind_i18n' => $course->art->toArray(), + 'kind_i18n' => is_object($course->art) ? $course->art->toArray() : $course->art, 'ects' => $course->ects, 'maxmembers' => $course->admission_turnout, ]); diff --git a/lib/classes/coursewizardsteps/BasicDataWizardStep.php b/lib/classes/coursewizardsteps/BasicDataWizardStep.php index 225b8ff97ed..bb29f06ebb7 100644 --- a/lib/classes/coursewizardsteps/BasicDataWizardStep.php +++ b/lib/classes/coursewizardsteps/BasicDataWizardStep.php @@ -491,11 +491,12 @@ class BasicDataWizardStep implements CourseWizardStep 'coursetype' => $course->status, 'start_time' => $course->start_time, 'name' => $course->name, - 'name_i18n' => $course->name->toArray(), + 'name_i18n' => is_object($course->name) ? $course->name->toArray() : $course->name, 'number' => $course->veranstaltungsnummer, 'institute' => $course->institut_id, 'description' => $course->beschreibung, - 'description_i18n' => $course->beschreibung->toArray() + 'description_i18n' => is_object($course->beschreibung) ? + $course->beschreibung->toArray() : $course->beschreibung ]; $lecturers = $course->members->findBy('status', 'dozent')->pluck('user_id'); $data['lecturers'] = array_flip($lecturers); @@ -584,26 +585,31 @@ class BasicDataWizardStep implements CourseWizardStep */ protected function makeI18N($values, $indices) { - /** - * Create array for configured content languages - */ - $translations = array_combine( - array_keys($GLOBALS['CONTENT_LANGUAGES']), - array_fill(0, count($GLOBALS['CONTENT_LANGUAGES']), '') - ); + // We only need to do something if there are several content languages. + if (count($GLOBALS['CONTENT_LANGUAGES']) > 1) { + + /** + * Create array for configured content languages + */ + $translations = array_combine( + array_keys($GLOBALS['CONTENT_LANGUAGES']), + array_fill(0, count($GLOBALS['CONTENT_LANGUAGES']), '') + ); - foreach ($indices as $index) { - // There are values given => create an I18NString - if ($values[$index]) { + foreach ($indices as $index) { + // There are values given => create an I18NString + if ($values[$index]) { - $values[$index] = new I18NString($values[$index], $values[$index . '_i18n']); + $values[$index] = new I18NString($values[$index], $values[$index . '_i18n']); - // Current index is not set (yet), create an empty I18NString - } else { + // Current index is not set (yet), create an empty I18NString + } else { - $values[$index] = new I18NString('', $translations); + $values[$index] = new I18NString('', $translations); + } } + } return $values; -- GitLab