Skip to content

Commit

Permalink
pkp#9425 Make submission language selection and metadata forms indepe…
Browse files Browse the repository at this point in the history
…ndent from website language settings
  • Loading branch information
jyhein committed Nov 14, 2023
1 parent f166648 commit 2ad90cd
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 26 deletions.
3 changes: 1 addition & 2 deletions classes/author/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion classes/author/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions classes/publication/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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;
Expand Down
14 changes: 8 additions & 6 deletions classes/submission/PKPSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 1 addition & 8 deletions classes/submissionFile/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion pages/submission/PKPSubmissionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 2ad90cd

Please sign in to comment.