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/galley/Galley.php b/classes/galley/Galley.php index a3b35cec100..0f2bb715d7b 100644 --- a/classes/galley/Galley.php +++ b/classes/galley/Galley.php @@ -205,6 +205,7 @@ public function getLanguages(): array return collect([$this->getData('locale')]) ->concat($locales) ->flatten() + ->filter() ->unique() ->values() ->toArray(); diff --git a/classes/publication/PKPPublication.php b/classes/publication/PKPPublication.php index e796f1f7020..c4a4c83e016 100644 --- a/classes/publication/PKPPublication.php +++ b/classes/publication/PKPPublication.php @@ -466,6 +466,7 @@ public function getLanguages(array $additionalLocales = []): array ->concat($authorsLocales) ->concat($additionalLocales) ->flatten() + ->filter() ->unique() ->values() ->toArray(); 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..fa79cf66381 100644 --- a/classes/submission/PKPSubmission.php +++ b/classes/submission/PKPSubmission.php @@ -219,19 +219,22 @@ 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 ($this->getData('locale') ? 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() + ->filter() ->unique() ->values() ->toArray(); diff --git a/classes/submissionFile/SubmissionFile.php b/classes/submissionFile/SubmissionFile.php index ca640e8bb55..712beecf302 100644 --- a/classes/submissionFile/SubmissionFile.php +++ b/classes/submissionFile/SubmissionFile.php @@ -404,6 +404,7 @@ public function getLanguages(): array return collect([$this->getData('locale')]) ->concat($locales) ->flatten() + ->filter() ->unique() ->values() ->toArray(); 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')