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 3, 2023
1 parent cdbe159 commit ed48bba
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions classes/publication/PKPPublication.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ public function getLanguages(array $additionalLocales = []): array
->concat($additionalLocales)
->flatten()
->unique()
->values()
->toArray();
}
}
Expand Down
13 changes: 10 additions & 3 deletions classes/submissionFile/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,16 @@ protected function mapByProperties(array $props, SubmissionFile $submissionFile)
$output[$prop] = $submissionFile->getData($prop);
}

$publicationId = $submissionFile->getData('assocId') ? Repo::galley()->get($submissionFile->getData('assocId'))?->getData('publicationId') : null;
$publicationLocales = $publicationId ? Repo::publication()->get($publicationId)?->getLanguages() ?? [] : [];
$locales = array_values(array_unique(array_merge($this->context->getSupportedSubmissionMetadataLocales(), $publicationLocales, [$submissionFile->getData('locale')])));
$publicationLocales = !($assocId = $submissionFile->getData('assocId'))
? [$submissionFile->getData('locale')]
: Repo::submission()
->get($submissionFile->getData('submissionId'))
->getData('publications')
->first(fn ($p) => collect($p->getData(Application::get()->getName() === 'omp' ? 'publicationFormats' : 'galleys'))
->contains(fn ($item) => $item->getId() === $assocId))
->getLanguages();

$locales = array_values(array_unique(array_merge($this->context->getSupportedSubmissionMetadataLocales(), $publicationLocales)));

$output = $this->schemaService->addMissingMultilingualValues(
$this->schema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ public function __construct($submissionFile, $stageId, $reviewRound = null, $tem
}

$submissionLocale = $submissionFile->getData('locale');
$publicationLocaleNames = Repo::publication()->get(Repo::galley()->get($submissionFile->getData('assocId'))?->getData('publicationId'))?->getLanguageNames() ?? [];
$publicationLocaleNames = Repo::submission()
->get($submissionFile->getData('submissionId'))
->getData('publications')
->first(fn ($p) => collect($p->getData(Application::get()->getName() === 'omp' ? 'publicationFormats' : 'galleys'))
->contains(fn ($item) => $item->getId() === $submissionFile->getData('assocId')))
->getLanguageNames();
$localeNames = Application::get()->getRequest()->getContext()->getSupportedSubmissionMetadataLocaleNames() + $publicationLocaleNames;
ksort($localeNames);

Expand Down
3 changes: 2 additions & 1 deletion pages/authorDashboard/PKPAuthorDashboardHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public function setupTemplate($request)
$locales = collect($submissionContext->getSupportedSubmissionMetadataLocaleNames() + $latestPublication->getLanguageNames())
->map(fn (string $name, string $locale) => ['key' => $locale, 'label' => $name])
->sortBy('key')
->values()
->toArray();

$submissionApiUrl = $request->getDispatcher()->url($request, PKPApplication::ROUTE_API, $submissionContext->getData('urlPath'), 'submissions/' . $submission->getId());
Expand Down Expand Up @@ -392,8 +393,8 @@ protected function getLocalizedForm(\PKP\components\forms\FormComponent $form, P

$config['supportedFormLocales'] = collect($context->getSupportedSubmissionMetadataLocaleNames() + $publication->getLanguageNames())
->map(fn (string $name, string $locale) => ['key' => $locale, 'label' => $name])
->values()
->sortBy([fn (array $a, array $b) => $a['key'] === $primaryLocale || $a['key'] < $b['key'] ? -1 : 1])
->values()
->toArray();

return $config;
Expand Down
3 changes: 2 additions & 1 deletion pages/workflow/PKPWorkflowHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public function index($args, $request)
$locales = collect($submissionContext->getSupportedSubmissionMetadataLocaleNames() + $latestPublication->getLanguageNames())
->map(fn (string $name, string $locale) => ['key' => $locale, 'label' => $name])
->sortBy('key')
->values()
->toArray();

$submissionApiUrl = $request->getDispatcher()->url($request, Application::ROUTE_API, $submissionContext->getData('urlPath'), 'submissions/' . $submission->getId());
Expand Down Expand Up @@ -844,8 +845,8 @@ protected function getLocalizedForm(\PKP\components\forms\FormComponent $form, P

$config['supportedFormLocales'] = collect($context->getSupportedSubmissionMetadataLocaleNames() + $publication->getLanguageNames())
->map(fn (string $name, string $locale) => ['key' => $locale, 'label' => $name])
->values()
->sortBy([fn (array $a, array $b) => $a['key'] === $primaryLocale || $a['key'] < $b['key'] ? -1 : 1])
->values()
->toArray();

return $config;
Expand Down

0 comments on commit ed48bba

Please sign in to comment.