From 8e3067b3a93d4979fc5000b35d78f001f5405a16 Mon Sep 17 00:00:00 2001 From: jyhein <124268211+jyhein@users.noreply.github.com> Date: Fri, 27 Oct 2023 08:33:26 +0300 Subject: [PATCH] pkp/pkp-lib#9425 Make submission language selection and metadata forms independent from website language settings --- classes/install/Upgrade.php | 4 ++-- classes/publication/Repository.php | 3 +-- classes/publication/maps/Schema.php | 3 +-- classes/submission/Repository.php | 3 +-- classes/submission/maps/Schema.php | 7 +++++-- .../grid/articleGalleys/form/ArticleGalleyForm.php | 7 ++----- dbscripts/xml/upgrade.xml | 1 + pages/workflow/WorkflowHandler.php | 11 ++++++----- 8 files changed, 19 insertions(+), 20 deletions(-) diff --git a/classes/install/Upgrade.php b/classes/install/Upgrade.php index 93eeec7f20c..13b5eeaba71 100644 --- a/classes/install/Upgrade.php +++ b/classes/install/Upgrade.php @@ -319,8 +319,8 @@ public function getSetting($journalId, $name, $locale = null) // journal_settings // Consider array setting values from the setting names: - // supportedFormLocales, supportedLocales, supportedAddedSubmissionLocales, supportedSubmissionLocales, supportedDefaultSubmissionLocale, supportedSubmissionMetadataLocales - $settingNames = "('supportedFormLocales', 'supportedLocales', 'supportedAddedSubmissionLocales', 'supportedSubmissionLocales', 'supportedDefaultSubmissionLocale', 'supportedSubmissionMetadataLocales')"; + // supportedFormLocales, supportedLocales, supportedSubmissionLocales + $settingNames = "('supportedFormLocales', 'supportedLocales', 'supportedSubmissionLocales')"; // As a precaution use $oldLocaleStringLength, to exclude that the text contain the old locale string $settingValueResult = $journalSettingsDao->retrieve('SELECT * FROM journal_settings WHERE setting_name IN ' . $settingNames . ' AND setting_value LIKE ? AND setting_type = \'object\'', ['%' . $oldLocaleStringLength . ':"' . $oldLocale . '%']); foreach ($settingValueResult as $row) { diff --git a/classes/publication/Repository.php b/classes/publication/Repository.php index e6efeec3b58..5d2da760887 100644 --- a/classes/publication/Repository.php +++ b/classes/publication/Repository.php @@ -42,8 +42,7 @@ public function validate($publication, array $props, Submission $submission, Con $errors = parent::validate($publication, $props, $submission, $context); $primaryLocale = $submission->getData('locale'); - $allowedLocales = $context->getSupportedSubmissionMetadataLocales(); - in_array($primaryLocale, $allowedLocales) || array_push($allowedLocales, $primaryLocale); + $allowedLocales = array_values(array_unique(array_merge($context->getSupportedSubmissionMetadataLocales(), $publication?->getLanguages() ?? [$primaryLocale]))); // Ensure that the specified section exists $section = null; diff --git a/classes/publication/maps/Schema.php b/classes/publication/maps/Schema.php index f633eee37f5..4250afa5400 100644 --- a/classes/publication/maps/Schema.php +++ b/classes/publication/maps/Schema.php @@ -49,8 +49,7 @@ protected function mapByProperties(array $props, Publication $publication, bool ); } - $locales = $this->context->getSupportedSubmissionMetadataLocales(); - in_array($primaryLocale = $this->submission->getData('locale'), $locales) || array_push($locales, $primaryLocale); + $locales = $publication->getLanguages($this->context->getSupportedSubmissionMetadataLocales()); $output = $this->schemaService->addMissingMultilingualValues(PKPSchemaService::SCHEMA_PUBLICATION, $output, $locales); diff --git a/classes/submission/Repository.php b/classes/submission/Repository.php index 682fdb74bc3..8a49c7c53bc 100644 --- a/classes/submission/Repository.php +++ b/classes/submission/Repository.php @@ -80,8 +80,7 @@ public function validateSubmit(Submission $submission, Context $context): array $abstracts = $publication->getData('abstract'); if ($abstracts) { $abstractErrors = []; - $allowedLocales = $context->getSupportedSubmissionMetadataLocales(); - in_array($locale, $allowedLocales) || array_push($allowedLocales, $locale); + $allowedLocales = $publication->getLanguages($context->getSupportedSubmissionMetadataLocales()); foreach ($allowedLocales as $localeKey) { $abstract = $publication->getData('abstract', $localeKey); $wordCount = $abstract ? PKPString::getWordCount($abstract) : 0; diff --git a/classes/submission/maps/Schema.php b/classes/submission/maps/Schema.php index 72601a999b1..12f2097c384 100644 --- a/classes/submission/maps/Schema.php +++ b/classes/submission/maps/Schema.php @@ -36,8 +36,11 @@ protected function mapByProperties(array $props, Submission $submission): array ); } - $locales = $this->context->getSupportedSubmissionMetaDataLocales(); - in_array($primaryLocale = $submission->getData('locale'), $locales) || array_push($locales, $primaryLocale); + $locales = $this->context->getSupportedSubmissionMetadataLocales(); + + if (!in_array($primaryLocale = $submission->getData('locale'), $locales)) { + $locales[] = $primaryLocale; + } $output = $this->schemaService->addMissingMultilingualValues($this->schemaService::SCHEMA_SUBMISSION, $output, $locales); diff --git a/controllers/grid/articleGalleys/form/ArticleGalleyForm.php b/controllers/grid/articleGalleys/form/ArticleGalleyForm.php index 3aebab4ca76..174862cbf57 100644 --- a/controllers/grid/articleGalleys/form/ArticleGalleyForm.php +++ b/controllers/grid/articleGalleys/form/ArticleGalleyForm.php @@ -25,7 +25,6 @@ use APP\template\TemplateManager; use PKP\form\Form; use PKP\galley\Galley; -use PKP\i18n\LocaleMetadata; class ArticleGalleyForm extends Form { @@ -63,8 +62,7 @@ public function __construct($request, $submission, $publication, $articleGalley $this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this)); // Ensure a locale is provided and valid - $submissionLocale = $submission->getData('locale'); - $locales = $request->getJournal()->getSupportedSubmissionMetadataLocaleNames() + [$submissionLocale => (new LocaleMetadata($submissionLocale))->getDisplayName(null, false)]; + $locales = $request->getJournal()->getSupportedSubmissionMetadataLocaleNames() + $publication->getLanguageNames(); $this->addCheck( new \PKP\form\validation\FormValidator( $this, @@ -94,8 +92,7 @@ public function fetch($request, $template = null, $display = false) ]); } - $submissionLocale = $this->_submission->getData('locale'); - $supportedLocales = $request->getContext()->getSupportedSubmissionMetadataLocaleNames() + [$submissionLocale => (new LocaleMetadata($submissionLocale))->getDisplayName(null, false)]; + $supportedLocales = $request->getContext()->getSupportedSubmissionMetadataLocaleNames() + $this->_publication->getLanguageNames(); ksort($supportedLocales); $templateMgr->assign([ diff --git a/dbscripts/xml/upgrade.xml b/dbscripts/xml/upgrade.xml index 23bc2f050f0..a43f9626112 100644 --- a/dbscripts/xml/upgrade.xml +++ b/dbscripts/xml/upgrade.xml @@ -220,6 +220,7 @@ + diff --git a/pages/workflow/WorkflowHandler.php b/pages/workflow/WorkflowHandler.php index 2e55cb9de8e..ffbff0658f8 100644 --- a/pages/workflow/WorkflowHandler.php +++ b/pages/workflow/WorkflowHandler.php @@ -85,12 +85,13 @@ public function setupIndex($request) $submissionContext = Services::get('context')->get($submission->getContextId()); } - $locales = $submissionContext->getSupportedSubmissionMetadataLocaleNames() + [$submission->getData('locale') => (new \PKP\i18n\LocaleMetadata($submission->getData('locale')))->getDisplayName(null, false)]; - $locales = array_map(fn (string $locale, string $name) => ['key' => $locale, 'label' => $name], array_keys($locales), $locales); - ksort($locales); - $latestPublication = $submission->getLatestPublication(); + $locales = collect($submissionContext->getSupportedSubmissionMetadataLocaleNames() + $latestPublication->getLanguageNames()) + ->map(fn (string $name, string $locale) => ['key' => $locale, 'label' => $name]) + ->sortBy('key') + ->toArray(); + $latestPublicationApiUrl = $request->getDispatcher()->url($request, Application::ROUTE_API, $submissionContext->getPath(), 'submissions/' . $submission->getId() . '/publications/' . $latestPublication->getId()); $temporaryFileApiUrl = $request->getDispatcher()->url($request, Application::ROUTE_API, $submissionContext->getPath(), 'temporaryFiles'); $issueApiUrl = $request->getDispatcher()->url($request, Application::ROUTE_API, $submissionContext->getData('urlPath'), 'issues/__issueId__'); @@ -114,7 +115,7 @@ class_exists(\APP\components\forms\publication\AssignToIssueForm::class); // For ]); $components = $templateMgr->getState('components'); - $components[FORM_ISSUE_ENTRY] = $this->getLocalizedForm($issueEntryForm, $submission, $submissionContext); + $components[FORM_ISSUE_ENTRY] = $this->getLocalizedForm($issueEntryForm, $latestPublication, $submissionContext); // Add payments form if enabled $paymentManager = Application::getPaymentManager($submissionContext);