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 27, 2023
1 parent f166648 commit d022a9d
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 28 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
1 change: 1 addition & 0 deletions classes/galley/Galley.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public function getLanguages(): array
return collect([$this->getData('locale')])
->concat($locales)
->flatten()
->filter()
->unique()
->values()
->toArray();
Expand Down
2 changes: 1 addition & 1 deletion classes/galley/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected function mapByProperties(array $props, Galley $galley): array
}
}

$locales = $this->publication->getLanguages(array_merge($this->context->getSupportedSubmissionMetadataLocales(), $galley->getLanguages()));
$locales = $this->publication->getLanguages($this->context->getSupportedSubmissionMetadataLocales(), $galley->getLanguages());

$output = $this->schemaService->addMissingMultilingualValues($this->schema, $output, $locales);

Expand Down
3 changes: 2 additions & 1 deletion classes/publication/PKPPublication.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public function getLanguageNames(int $langLocaleStatus = LocaleMetadata::LANGUAG
* Publication: locale, multilingual metadata props
* Authors: multilingual props
*/
public function getLanguages(array $additionalLocales = []): array
public function getLanguages(?array ...$additionalLocales): array
{
$getMProps = fn (string $schema) => Services::get('schema')->getMultilingualProps($schema);
$metadataprops = $getMProps(PKPSchemaService::SCHEMA_PUBLICATION);
Expand All @@ -466,6 +466,7 @@ public function getLanguages(array $additionalLocales = []): array
->concat($authorsLocales)
->concat($additionalLocales)
->flatten()
->filter()
->unique()
->values()
->toArray();
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
15 changes: 9 additions & 6 deletions classes/submission/PKPSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions classes/submissionFile/SubmissionFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ public function getLanguages(): array
return collect([$this->getData('locale')])
->concat($locales)
->flatten()
->filter()
->unique()
->values()
->toArray();
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($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 d022a9d

Please sign in to comment.