From 2ad90cdc8b868a8e498f41e6d2c7668e3a755023 Mon Sep 17 00:00:00 2001 From: jyhein <124268211+jyhein@users.noreply.github.com> Date: Tue, 14 Nov 2023 14:52:29 +0200 Subject: [PATCH] pkp/pkp-lib#9425 Make submission language selection and metadata forms independent from website language settings --- classes/author/Repository.php | 3 +-- classes/author/maps/Schema.php | 2 +- classes/publication/Repository.php | 4 ++-- classes/submission/PKPSubmission.php | 14 ++++++++------ classes/submissionFile/maps/Schema.php | 9 +-------- .../form/SubmissionFilesMetadataForm.php | 7 +------ pages/submission/PKPSubmissionHandler.php | 2 +- 7 files changed, 15 insertions(+), 26 deletions(-) diff --git a/classes/author/Repository.php b/classes/author/Repository.php index 3848802bb19..d44522acb9b 100644 --- a/classes/author/Repository.php +++ b/classes/author/Repository.php @@ -100,8 +100,7 @@ public function validate($author, $props, Submission $submission, Context $conte { $schemaService = Services::get('schema'); $primaryLocale = $submission->getData('locale'); - $publicationLocales = isset($props['publicationId']) ? Repo::publication()->get($props['publicationId'])?->getLanguages() ?? [$primaryLocale] : [$primaryLocale]; - $allowedLocales = array_values(array_unique(array_merge($context->getSupportedSubmissionMetadataLocales(), $publicationLocales))); + $allowedLocales = $submission->getPublicationLanguages($context->getSupportedSubmissionMetadataLocales()); $validator = ValidatorFactory::make( $props, diff --git a/classes/author/maps/Schema.php b/classes/author/maps/Schema.php index 47f9fd25b73..45bda26bee5 100644 --- a/classes/author/maps/Schema.php +++ b/classes/author/maps/Schema.php @@ -106,7 +106,7 @@ protected function mapByProperties(array $props, Author $item): array } } - $locales = Repo::publication()->get($item->getData('publicationId'))->getLanguages($this->context->getSupportedSubmissionMetadataLocales()); + $locales = Repo::submission()->get(Repo::publication()->get($item->getData('publicationId'))->getData('submissionId'))->getPublicationLanguages($this->context->getSupportedSubmissionMetadataLocales()); $output = $this->schemaService->addMissingMultilingualValues($this->schema, $output, $locales); diff --git a/classes/publication/Repository.php b/classes/publication/Repository.php index 450310d1e04..a3bbc80d64f 100644 --- a/classes/publication/Repository.php +++ b/classes/publication/Repository.php @@ -134,7 +134,7 @@ public function getDateBoundaries(Collector $query): object public function validate(?Publication $publication, array $props, Submission $submission, Context $context): array { $primaryLocale = $submission->getData('locale'); - $allowedLocales = array_values(array_unique(array_merge($context->getSupportedSubmissionMetadataLocales(), $publication?->getLanguages() ?? [$primaryLocale]))); + $allowedLocales = $submission->getpublicationLanguages($context->getSupportedSubmissionMetadataLocales()); $errors = []; @@ -286,7 +286,7 @@ public function add(Publication $publication): int $submissionContext = Services::get('context')->get($submission->getData('contextId')); } - $supportedLocales = $publication->getLanguages($submissionContext->getSupportedSubmissionMetadataLocales()); + $supportedLocales = $submission->getPublicationLanguages($submissionContext->getSupportedSubmissionMetadataLocales()); foreach ($supportedLocales as $localeKey) { if (!array_key_exists($localeKey, $publication->getData('coverImage'))) { continue; diff --git a/classes/submission/PKPSubmission.php b/classes/submission/PKPSubmission.php index 75a804390e0..f5f69faa2fe 100644 --- a/classes/submission/PKPSubmission.php +++ b/classes/submission/PKPSubmission.php @@ -219,18 +219,20 @@ public function getDAO(): DAO */ public function getPublicationLanguageNames(int $langLocaleStatus = LocaleMetadata::LANGUAGE_LOCALE_WITHOUT): array { - return collect($this->getData('publications')) - ->flatMap(fn (Publication $p): array => $p->getLanguageNames($langLocaleStatus)) - ->toArray(); + return Locale::getFormattedDisplayNames([$this->getData('locale')], null, $langLocaleStatus) + + collect($this->getData('publications')) + ->flatMap(fn (Publication $p): array => $p->getLanguageNames($langLocaleStatus)) + ->toArray(); } /** * Get metadata languages from publications */ - public function getPublicationLanguages(): array + public function getPublicationLanguages(array $additionalLanguages = []): array { - return $this->getData('publications') - ->map(fn (Publication $p): array => $p->getLanguages()) + return collect([$this->getData('locale')]) + ->concat($this->getData('publications')->map(fn (Publication $p): array => $p->getLanguages())) + ->concat($additionalLanguages) ->flatten() ->unique() ->values() diff --git a/classes/submissionFile/maps/Schema.php b/classes/submissionFile/maps/Schema.php index 9f9fcac10b2..3aee4f9d3aa 100644 --- a/classes/submissionFile/maps/Schema.php +++ b/classes/submissionFile/maps/Schema.php @@ -226,14 +226,7 @@ protected function mapByProperties(array $props, SubmissionFile $submissionFile) $output[$prop] = $submissionFile->getData($prop); } - $submission = Repo::submission()->get($submissionFile->getData('submissionId')); - $publicationLanguages = $submission->getData('publications') - ->first(fn ($p) => collect($p->getData(Application::get()->getName() === 'omp' ? 'publicationFormats' : 'galleys') ?? []) - ->contains(fn ($item) => $item->getId() === $submissionFile->getData('assocId'))) - ?->getLanguages() - ?? $submission->getPublicationLanguages(); - - $locales = array_values(array_unique(array_merge($this->context->getSupportedSubmissionMetadataLocales(), $publicationLanguages, $submissionFile->getLanguages()))); + $locales = Repo::submission()->get($submissionFile->getData('submissionId'))->getPublicationLanguages(array_merge($this->context->getSupportedSubmissionMetadataLocales(), $submissionFile->getLanguages())); $output = $this->schemaService->addMissingMultilingualValues( $this->schema, diff --git a/controllers/wizard/fileUpload/form/SubmissionFilesMetadataForm.php b/controllers/wizard/fileUpload/form/SubmissionFilesMetadataForm.php index 5d39b2b2a72..77c1271dfb1 100644 --- a/controllers/wizard/fileUpload/form/SubmissionFilesMetadataForm.php +++ b/controllers/wizard/fileUpload/form/SubmissionFilesMetadataForm.php @@ -51,12 +51,7 @@ public function __construct($submissionFile, $stageId, $reviewRound = null, $tem } $submissionLocale = $submissionFile->getData('locale'); - $submission = Repo::submission()->get($submissionFile->getData('submissionId')); - $publicationLanguageNames = $submission->getData('publications') - ->first(fn ($p) => collect($p->getData(Application::get()->getName() === 'omp' ? 'publicationFormats' : 'galleys') ?? []) - ->contains(fn ($item) => $item->getId() === $submissionFile->getData('assocId'))) - ?->getLanguageNames() - ?? $submission->getPublicationLanguageNames(); + $publicationLanguageNames = Repo::submission()->get($submissionFile->getData('submissionId'))->getPublicationLanguageNames(); $localeNames = Application::get()->getRequest()->getContext()->getSupportedSubmissionMetadataLocaleNames() + $publicationLanguageNames + $submissionFile->getLanguageNames(); ksort($localeNames); diff --git a/pages/submission/PKPSubmissionHandler.php b/pages/submission/PKPSubmissionHandler.php index 1760d3ef7e3..4ecc8d4a743 100644 --- a/pages/submission/PKPSubmissionHandler.php +++ b/pages/submission/PKPSubmissionHandler.php @@ -186,7 +186,7 @@ protected function showWizard(array $args, Request $request, Submission $submiss } - $supportedLocales = $context->getSupportedSubmissionMetadataLocaleNames() + $publication->getLanguageNames(); + $supportedLocales = $context->getSupportedSubmissionMetadataLocaleNames() + $submission->getPublicationLanguageNames(); $formLocales = collect($supportedLocales) ->map(fn (string $name, string $locale) => ['key' => $locale, 'label' => $name]) ->sortBy('key')