diff --git a/api/v1/vocabs/PKPVocabController.php b/api/v1/vocabs/PKPVocabController.php
index 5aaecf9574f..6fc2dcef8a7 100644
--- a/api/v1/vocabs/PKPVocabController.php
+++ b/api/v1/vocabs/PKPVocabController.php
@@ -18,6 +18,7 @@
namespace PKP\API\v1\vocabs;
use APP\core\Application;
+use APP\facades\Repo;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
@@ -107,9 +108,9 @@ public function getMany(Request $illuminateRequest): JsonResponse
$vocab = $requestParams['vocab'] ?? '';
$locale = $requestParams['locale'] ?? Locale::getLocale();
$term = $requestParams['term'] ?? null;
- $isSubmissionPrimaryLocale = isset($requestParams['submissionId']) && $locale === (Repo::submission()->get((int) $requestParams['submissionId']))?->getData('locale');
+ $locales = array_merge($context->getSupportedSubmissionMetadataLocales(), isset($requestParams['publicationId']) ? Repo::publication()->get((int) $requestParams['publicationId'])?->getLanguages() ?? [] : []);
- if (!in_array($locale, $context->getData('supportedSubmissionLocales'))) {
+ if (!in_array($locale, $locales)) {
return response()->json([
'error' => __('api.vocabs.400.localeNotSupported', ['locale' => $locale]),
], Response::HTTP_BAD_REQUEST);
diff --git a/classes/author/Repository.php b/classes/author/Repository.php
index 90532f07776..3848802bb19 100644
--- a/classes/author/Repository.php
+++ b/classes/author/Repository.php
@@ -100,8 +100,8 @@ public function validate($author, $props, Submission $submission, Context $conte
{
$schemaService = Services::get('schema');
$primaryLocale = $submission->getData('locale');
- $allowedLocales = $context->getSupportedSubmissionMetadataLocales();
- in_array($primaryLocale, $allowedLocales) || array_push($allowedLocales, $primaryLocale);
+ $publicationLocales = isset($props['publicationId']) ? Repo::publication()->get($props['publicationId'])?->getLanguages() ?? [$primaryLocale] : [$primaryLocale];
+ $allowedLocales = array_values(array_unique(array_merge($context->getSupportedSubmissionMetadataLocales(), $publicationLocales)));
$validator = ValidatorFactory::make(
$props,
diff --git a/classes/author/maps/Schema.php b/classes/author/maps/Schema.php
index 3cdb2d7fd7e..47f9fd25b73 100644
--- a/classes/author/maps/Schema.php
+++ b/classes/author/maps/Schema.php
@@ -106,7 +106,9 @@ protected function mapByProperties(array $props, Author $item): array
}
}
- $output = $this->schemaService->addMissingMultilingualValues($this->schema, $output, $this->context->getSupportedSubmissionMetadataLocales());
+ $locales = Repo::publication()->get($item->getData('publicationId'))->getLanguages($this->context->getSupportedSubmissionMetadataLocales());
+
+ $output = $this->schemaService->addMissingMultilingualValues($this->schema, $output, $locales);
ksort($output);
diff --git a/classes/context/Context.php b/classes/context/Context.php
index 826e5a28aa9..f1edb42dc58 100644
--- a/classes/context/Context.php
+++ b/classes/context/Context.php
@@ -395,10 +395,8 @@ public function getSupportedLocaleNames(int $langLocaleStatus = LocaleMetadata::
/**
* Get the supported added submission locales.
- *
- * @return array
*/
- public function getSupportedAddedSubmissionLocales()
+ public function getSupportedAddedSubmissionLocales(): array
{
return $this->getData('supportedAddedSubmissionLocales');
}
@@ -407,42 +405,42 @@ public function getSupportedAddedSubmissionLocales()
* Return associative array of added locales supported by submissions on the
* context.
*
- * @param int $langLocaleStatus The const value of one of LocaleMetadata:LANGUAGE_LOCALE_*
- *
- * @return array
+ * $langLocaleStatus The const value of one of LocaleMetadata:LANGUAGE_LOCALE_*
*/
- public function getSupportedAddedSubmissionLocaleNames(int $langLocaleStatus = LocaleMetadata::LANGUAGE_LOCALE_WITHOUT)
+ public function getSupportedAddedSubmissionLocaleNames(int $langLocaleStatus = LocaleMetadata::LANGUAGE_LOCALE_WITHOUT): array
{
- return $this->getData('supportedAddedSubmissionLocaleNames') ?? Locale::getFormattedDisplayNames($this->getSupportedAddedSubmissionLocales(), null, $langLocaleStatus);
+ return Locale::getFormattedDisplayNames($this->getSupportedAddedSubmissionLocales(), null, $langLocaleStatus);
}
/**
* Get the supported default submission locale.
*/
- public function getSupportedDefaultSubmissionLocale(): ?string
+ public function getSupportedDefaultSubmissionLocale(): string
{
return $this->getData('supportedDefaultSubmissionLocale');
}
/**
* Return string default submission locale supported by the site.
+ *
* $langLocaleStatus The const value of one of LocaleMetadata:LANGUAGE_LOCALE_*
*/
public function getSupportedDefaultSubmissionLocaleName(int $langLocaleStatus = LocaleMetadata::LANGUAGE_LOCALE_WITHOUT): string
{
- return Locale::getFormattedDisplayNames($this->getSupportedDefaultSubmissionLocale(), null, $langLocaleStatus);
+ return Locale::getFormattedDisplayNames([$locale = $this->getSupportedDefaultSubmissionLocale()], null, $langLocaleStatus)[$locale];
}
/**
* Get the supported metadata locales.
*/
- public function getSupportedSubmissionMetadataLocales(): ?array
+ public function getSupportedSubmissionMetadataLocales(): array
{
return $this->getData('supportedSubmissionMetadataLocales');
}
/**
* Return associative array of all locales supported by submission metadata forms on the site.
+ *
* $langLocaleStatus The const value of one of LocaleMetadata:LANGUAGE_LOCALE_*
*/
public function getSupportedSubmissionMetadataLocaleNames(int $langLocaleStatus = LocaleMetadata::LANGUAGE_LOCALE_WITHOUT): array
diff --git a/classes/galley/maps/Schema.php b/classes/galley/maps/Schema.php
index c9386eb27ab..b13e478988f 100644
--- a/classes/galley/maps/Schema.php
+++ b/classes/galley/maps/Schema.php
@@ -140,8 +140,7 @@ protected function mapByProperties(array $props, Galley $galley): array
}
}
- $locales = $this->context->getSupportedSubmissionMetaDataLocales();
- in_array($primaryLocale = $this->submission->getData('locale'), $locales) || array_push($locales, $primaryLocale);
+ $locales = $this->publication->getLanguages($this->context->getSupportedSubmissionMetadataLocales());
$output = $this->schemaService->addMissingMultilingualValues($this->schema, $output, $locales);
diff --git a/classes/migration/upgrade/v3_5_0/I9425_SeparateUIAndSubmissionLocales.php b/classes/migration/upgrade/v3_5_0/I9425_SeparateUIAndSubmissionLocales.php
new file mode 100644
index 00000000000..51abe0c4331
--- /dev/null
+++ b/classes/migration/upgrade/v3_5_0/I9425_SeparateUIAndSubmissionLocales.php
@@ -0,0 +1,65 @@
+getContextSettingsTable())->insert(
+ [
+ $this->getContextIdColumn() => $contextId,
+ 'locale' => '',
+ 'setting_name' => $settingName,
+ 'setting_value' => $settingValue,
+ ]
+ );
+ };
+ $pluck = fn (int $contextId, string $settingName) => DB::table($this->getContextSettingsTable())
+ ->where($this->getContextIdColumn(), '=', $contextId)
+ ->where('setting_name', '=', $settingName)
+ ->pluck('setting_value')[0];
+
+ foreach (DB::table($this->getContextTable())->select('primary_locale', $this->getContextIdColumn())->get() as $localeId) {
+ // supportedDefaultSubmissionLocale from primary locale
+ $insert($localeId->{$this->getContextIdColumn()}, 'supportedDefaultSubmissionLocale', $localeId->primary_locale);
+ // supportedAddedSubmissionLocales from supportedLocales
+ $insert($localeId->{$this->getContextIdColumn()}, 'supportedAddedSubmissionLocales', $pluck($localeId->{$this->getContextIdColumn()}, 'supportedLocales'));
+ // supportedSubmissionMetadataLocales from supportedSubmissionLocales
+ $insert($localeId->{$this->getContextIdColumn()}, 'supportedSubmissionMetadataLocales', $pluck($localeId->{$this->getContextIdColumn()}, 'supportedSubmissionLocales'));
+ }
+ }
+
+ /**
+ * Reverse the downgrades
+ */
+ public function down(): void
+ {
+ throw new DowngradeNotSupportedException();
+ }
+}
diff --git a/classes/publication/PKPPublication.php b/classes/publication/PKPPublication.php
index 29493472246..e3cbb6a4596 100644
--- a/classes/publication/PKPPublication.php
+++ b/classes/publication/PKPPublication.php
@@ -19,9 +19,13 @@
namespace PKP\publication;
use APP\author\Author;
+use APP\core\Services;
use APP\facades\Repo;
use PKP\core\Core;
use PKP\core\PKPString;
+use PKP\facades\Locale;
+use PKP\i18n\LocaleMetadata;
+use PKP\services\PKPSchemaService;
use PKP\userGroup\UserGroup;
class PKPPublication extends \PKP\core\DataObject
@@ -431,6 +435,40 @@ public function setStoredPubId($pubIdType, $pubId)
$this->setData('pub-id::' . $pubIdType, $pubId);
}
}
+
+ /**
+ * Get metadata language names
+ */
+ public function getLanguageNames(int $langLocaleStatus = LocaleMetadata::LANGUAGE_LOCALE_WITHOUT): array
+ {
+ return Locale::getFormattedDisplayNames($this->getLanguages(), null, $langLocaleStatus);
+ }
+
+ /**
+ * Get languages from locale, metadata, and authors' props.
+ * Include optional additional languages.
+ *
+ * Publication: locale, multilingual metadata props
+ * Authors: multilingual props
+ */
+ public function getLanguages(array $additionalLocales = []): array
+ {
+ $getMProps = fn (string $schema) => Services::get('schema')->getMultilingualProps($schema);
+ $metadataprops = $getMProps(PKPSchemaService::SCHEMA_PUBLICATION);
+ $authorProps = $getMProps(PKPSchemaService::SCHEMA_AUTHOR);
+
+ $getlocales = fn (array $props, object $item) => array_map(fn (string $prop) => array_keys($item->getData($prop) ?? []), $props);
+ $metadataLocales = $getlocales($metadataprops, $this);
+ $authorsLocales = $this->getData('authors')?->map(fn (Author $author) => $getlocales($authorProps, $author)) ?? [];
+
+ return collect([$this->getData('locale')])
+ ->concat($metadataLocales)
+ ->concat($authorsLocales)
+ ->concat($additionalLocales)
+ ->flatten()
+ ->unique()
+ ->toArray();
+ }
}
if (!PKP_STRICT_MODE) {
class_alias('\PKP\publication\PKPPublication', '\PKPPublication');
diff --git a/classes/publication/Repository.php b/classes/publication/Repository.php
index 5ded1c8e95d..450310d1e04 100644
--- a/classes/publication/Repository.php
+++ b/classes/publication/Repository.php
@@ -134,8 +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 = $context->getSupportedSubmissionMetadataLocales();
- in_array($primaryLocale, $allowedLocales) || array_push($allowedLocales, $primaryLocale);
+ $allowedLocales = array_values(array_unique(array_merge($context->getSupportedSubmissionMetadataLocales(), $publication?->getLanguages() ?? [$primaryLocale])));
$errors = [];
@@ -287,8 +286,7 @@ public function add(Publication $publication): int
$submissionContext = Services::get('context')->get($submission->getData('contextId'));
}
- $supportedLocales = $submissionContext->getSupportedSubmissionMetadataLocales();
- in_array($primaryLocale = $submission->getData('locale'), $supportedLocales) || array_push($supportedLocales, $primaryLocale);
+ $supportedLocales = $publication->getLanguages($submissionContext->getSupportedSubmissionMetadataLocales());
foreach ($supportedLocales as $localeKey) {
if (!array_key_exists($localeKey, $publication->getData('coverImage'))) {
continue;
@@ -385,8 +383,7 @@ public function edit(Publication $publication, array $params): Publication
$submissionContext = Services::get('context')->get($submission->getData('contextId'));
}
- $supportedLocales = $submissionContext->getSupportedSubmissionMetadataLocales();
- in_array($primaryLocale = $submission->getData('locale'), $supportedLocales) || array_push($supportedLocales, $primaryLocale);
+ $supportedLocales = $publication->getLanguages($submissionContext->getSupportedSubmissionMetadataLocales());
foreach ($supportedLocales as $localeKey) {
if (!array_key_exists($localeKey, $params['coverImage'])) {
continue;
diff --git a/classes/submission/Repository.php b/classes/submission/Repository.php
index 85674fa4393..ccfa34d3151 100644
--- a/classes/submission/Repository.php
+++ b/classes/submission/Repository.php
@@ -257,7 +257,10 @@ public function validate(?Submission $submission, array $props, Context $context
{
$primaryLocale = $props['locale'] ?? $submission?->getData('locale') ?? $context->getSupportedDefaultSubmissionLocale();
$allowedLocales = $context->getSupportedSubmissionLocales();
- in_array($primaryLocale, $allowedLocales) || array_push($allowedLocales, $primaryLocale);
+
+ if (!in_array($primaryLocale, $allowedLocales) ) {
+ $allowedLocales[] = $primaryLocale;
+ }
$errors = [];
diff --git a/classes/submissionFile/maps/Schema.php b/classes/submissionFile/maps/Schema.php
index 183db77d3d2..8e86ac5a514 100644
--- a/classes/submissionFile/maps/Schema.php
+++ b/classes/submissionFile/maps/Schema.php
@@ -226,8 +226,9 @@ protected function mapByProperties(array $props, SubmissionFile $submissionFile)
$output[$prop] = $submissionFile->getData($prop);
}
- $locales = $this->context->getSupportedSubmissionMetaDataLocales();
- in_array($submissionLocale = $submissionFile->getData('locale'), $locales) || array_push($locales, $submissionLocale);
+ $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')])));
$output = $this->schemaService->addMissingMultilingualValues(
$this->schema,
diff --git a/controllers/api/file/PKPManageFileApiHandler.php b/controllers/api/file/PKPManageFileApiHandler.php
index f74ee59fbd7..e929cb0c018 100644
--- a/controllers/api/file/PKPManageFileApiHandler.php
+++ b/controllers/api/file/PKPManageFileApiHandler.php
@@ -193,7 +193,7 @@ public function editMetadataTab($args, $request)
$submissionFile = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION_FILE);
$reviewRound = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_REVIEW_ROUND);
$stageId = $request->getUserVar('stageId');
- $form = new SubmissionFilesMetadataForm($submissionFile, $stageId, $request->getContext(), $reviewRound);
+ $form = new SubmissionFilesMetadataForm($submissionFile, $stageId, $reviewRound);
$form->setShowButtons(true);
return new JSONMessage(true, $form->fetch($request));
}
@@ -213,7 +213,7 @@ public function saveMetadata($args, $request)
$submissionFile = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION_FILE);
$reviewRound = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_REVIEW_ROUND);
$stageId = $request->getUserVar('stageId');
- $form = new SubmissionFilesMetadataForm($submissionFile, $stageId, $request->getContext(), $reviewRound);
+ $form = new SubmissionFilesMetadataForm($submissionFile, $stageId, $reviewRound);
$form->readInputData();
if ($form->validate()) {
$form->execute();
diff --git a/controllers/grid/languages/LanguageGridHandler.php b/controllers/grid/languages/LanguageGridHandler.php
index 74e52d0d61d..f5bb1edd897 100644
--- a/controllers/grid/languages/LanguageGridHandler.php
+++ b/controllers/grid/languages/LanguageGridHandler.php
@@ -23,6 +23,7 @@
use PKP\controllers\grid\GridColumn;
use PKP\controllers\grid\GridHandler;
use PKP\core\JSONMessage;
+use PKP\db\DAO;
use PKP\facades\Locale;
use PKP\notification\PKPNotification;
use PKP\security\Role;
@@ -137,19 +138,6 @@ public function saveLanguageSetting($args, $request)
}
$context = $contextService->edit($context, ['supportedSubmissionLocales' => $supportedSubmissionLocales], $request);
}
-
- if ($settingName == 'supportedSubmissionLocales') {
- // If someone tried to disable all submissions checkboxes, we should display an error message.
- $supportedSubmissionLocales = (array) $context->getSupportedSubmissionLocales();
- $key = array_search($locale, $supportedSubmissionLocales);
- if ($key !== false) {
- unset($supportedSubmissionLocales[$key]);
- }
- $supportedSubmissionLocales = array_values($supportedSubmissionLocales);
- if ($supportedSubmissionLocales == []) {
- return new JSONMessage(false, __('notification.localeSettingsCannotBeSaved'));
- }
- }
}
}
}
@@ -212,7 +200,7 @@ public function setContextPrimaryLocale($args, $request)
);
}
- return \PKP\db\DAO::getDataChangedEvent();
+ return DAO::getDataChangedEvent();
}
/**
@@ -252,7 +240,7 @@ public function setDefaultSubmissionLocale(array $args, Request $request): JSONM
);
}
- return \PKP\db\DAO::getDataChangedEvent();
+ return DAO::getDataChangedEvent();
}
//
diff --git a/controllers/grid/languages/form/AddLanguageForm.php b/controllers/grid/languages/form/AddLanguageForm.php
index 54a46444e57..ea067d5ba50 100644
--- a/controllers/grid/languages/form/AddLanguageForm.php
+++ b/controllers/grid/languages/form/AddLanguageForm.php
@@ -3,8 +3,8 @@
/**
* @file controllers/grid/languages/form/AddLanguageForm.php
*
- * Copyright (c) 2014-2023 Simon Fraser University
- * Copyright (c) 2003-2023 John Willinsky
+ * Copyright (c) 2023 Simon Fraser University
+ * Copyright (c) 2023 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class AddLanguageForm
@@ -108,8 +108,14 @@ public function execute(...$functionArgs)
if (in_array($context->getSupportedDefaultSubmissionLocale(), $removedLocales)) {
$context = $contextService->edit($context, ['supportedDefaultSubmissionLocale' => $locales[0]], $request);
- (in_array($locales[0], $submToAdd) || array_push($submToAdd, $locales[0]) && sort($submToAdd));
- (in_array($locales[0], $metaToAdd) || array_push($metaToAdd, $locales[0]) && sort($metaToAdd));
+ if (!in_array($locales[0], $submToAdd)) {
+ array_push($submToAdd, $locales[0]);
+ sort($submToAdd);
+ }
+ if (!in_array($locales[0], $metaToAdd)) {
+ array_push($metaToAdd, $locales[0]);
+ sort($metaToAdd);
+ }
}
$context = $contextService->edit($context, [
diff --git a/controllers/grid/settings/languages/SubmissionLanguageGridHandler.php b/controllers/grid/settings/languages/SubmissionLanguageGridHandler.php
index 73769cb306e..de1a9315402 100644
--- a/controllers/grid/settings/languages/SubmissionLanguageGridHandler.php
+++ b/controllers/grid/settings/languages/SubmissionLanguageGridHandler.php
@@ -3,8 +3,8 @@
/**
* @file controllers/grid/settings/languages/SubmissionLanguageGridHandler.php
*
- * Copyright (c) 2014-2023 Simon Fraser University
- * Copyright (c) 2000-2023 John Willinsky
+ * Copyright (c) 2023 Simon Fraser University
+ * Copyright (c) 2023 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class SubmissionLanguageGridHandler
diff --git a/controllers/wizard/fileUpload/FileUploadWizardHandler.php b/controllers/wizard/fileUpload/FileUploadWizardHandler.php
index 9dc9c4fb9ca..8b260fa5f64 100644
--- a/controllers/wizard/fileUpload/FileUploadWizardHandler.php
+++ b/controllers/wizard/fileUpload/FileUploadWizardHandler.php
@@ -456,7 +456,7 @@ public function editMetadata($args, $request)
$context = $request->getContext();
$submissionFile = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION_FILE);
- $form = new SubmissionFilesMetadataForm($submissionFile, $this->getStageId(), $context, $this->getReviewRound());
+ $form = new SubmissionFilesMetadataForm($submissionFile, $this->getStageId(), $this->getReviewRound());
$form->initData();
/** @var GenreDAO $genreDao */
diff --git a/controllers/wizard/fileUpload/form/SubmissionFilesMetadataForm.php b/controllers/wizard/fileUpload/form/SubmissionFilesMetadataForm.php
index efed3b95737..71a2c370338 100644
--- a/controllers/wizard/fileUpload/form/SubmissionFilesMetadataForm.php
+++ b/controllers/wizard/fileUpload/form/SubmissionFilesMetadataForm.php
@@ -16,6 +16,7 @@
namespace PKP\controllers\wizard\fileUpload\form;
+use APP\core\Application;
use APP\facades\Repo;
use APP\template\TemplateManager;
use PKP\db\DAORegistry;
@@ -40,19 +41,21 @@ class SubmissionFilesMetadataForm extends Form
*
* @param SubmissionFile $submissionFile
* @param int $stageId One of the WORKFLOW_STAGE_ID_* constants.
- * @param Context $context
* @param ReviewRound $reviewRound (optional) Current review round, if any.
* @param string $template Path and filename to template file (optional).
*/
- public function __construct($submissionFile, $stageId, $context, $reviewRound = null, $template = null)
+ public function __construct($submissionFile, $stageId, $reviewRound = null, $template = null)
{
if ($template === null) {
$template = 'controllers/wizard/fileUpload/form/submissionFileMetadataForm.tpl';
}
$submissionLocale = $submissionFile->getData('locale');
+ $publicationLocaleNames = Repo::publication()->get(Repo::galley()->get($submissionFile->getData('assocId'))?->getData('publicationId'))?->getLanguageNames() ?? [];
+ $localeNames = Application::get()->getRequest()->getContext()->getSupportedSubmissionMetadataLocaleNames() + $publicationLocaleNames;
+ ksort($localeNames);
- parent::__construct($template, true, $submissionLocale, $context->getSupportedSubmissionMetadataLocaleNames());
+ parent::__construct($template, true, $submissionLocale, $localeNames);
// Initialize the object.
$this->_submissionFile = $submissionFile;
diff --git a/pages/authorDashboard/PKPAuthorDashboardHandler.php b/pages/authorDashboard/PKPAuthorDashboardHandler.php
index c4a986a9a00..0cbef1726b6 100644
--- a/pages/authorDashboard/PKPAuthorDashboardHandler.php
+++ b/pages/authorDashboard/PKPAuthorDashboardHandler.php
@@ -35,7 +35,6 @@
use PKP\core\PKPApplication;
use PKP\core\PKPRequest;
use PKP\db\DAORegistry;
-use PKP\i18n\LocaleMetadata;
use PKP\log\SubmissionEmailLogDAO;
use PKP\log\SubmissionEmailLogEntry;
use PKP\security\authorization\AuthorDashboardAccessPolicy;
@@ -217,12 +216,13 @@ public function setupTemplate($request)
}
}
- $locales = $submissionContext->getSupportedSubmissionMetadataLocaleNames() + [$submission->getData('locale') => (new LocaleMetadata($submission->getData('locale')))->getDisplayName(null, false)];
- ksort($locales);
- $locales = array_map(fn (string $locale, string $name) => ['key' => $locale, 'label' => $name], array_keys($locales), $locales);
-
$latestPublication = $submission->getLatestPublication();
+ $locales = collect($submissionContext->getSupportedSubmissionMetadataLocaleNames() + $latestPublication->getLanguageNames())
+ ->map(fn (string $name, string $locale) => ['key' => $locale, 'label' => $name])
+ ->sortBy('key')
+ ->toArray();
+
$submissionApiUrl = $request->getDispatcher()->url($request, PKPApplication::ROUTE_API, $submissionContext->getData('urlPath'), 'submissions/' . $submission->getId());
$latestPublicationApiUrl = $request->getDispatcher()->url($request, PKPApplication::ROUTE_API, $submissionContext->getData('urlPath'), 'submissions/' . $submission->getId() . '/publications/' . $latestPublication->getId());
@@ -304,8 +304,8 @@ public function setupTemplate($request)
$state = [
'canEditPublication' => $canEditPublication,
'components' => [
- FORM_TITLE_ABSTRACT => $this->getLocalizedForm($titleAbstractForm, $submission, $submissionContext),
- FORM_CITATIONS => $this->getLocalizedForm($citationsForm, $submission, $submissionContext),
+ FORM_TITLE_ABSTRACT => $this->getLocalizedForm($titleAbstractForm, $latestPublication, $submissionContext),
+ FORM_CITATIONS => $this->getLocalizedForm($citationsForm, $latestPublication, $submissionContext),
$contributorsListPanel->id => $contributorsListPanel->getConfig(),
],
'currentPublication' => $currentPublicationProps,
@@ -328,7 +328,7 @@ public function setupTemplate($request)
];
// Add the metadata form if one or more metadata fields are enabled
- $vocabSuggestionUrlBase = $request->getDispatcher()->url($request, PKPApplication::ROUTE_API, $submissionContext->getData('urlPath'), 'vocabs', null, null, ['vocab' => '__vocab__', 'submissionId' => $submission->getId()]);
+ $vocabSuggestionUrlBase = $request->getDispatcher()->url($request, PKPApplication::ROUTE_API, $submissionContext->getData('urlPath'), 'vocabs', null, null, ['vocab' => '__vocab__', 'publicationId' => $latestPublication->getId()]);
$metadataForm = new PKPMetadataForm($latestPublicationApiUrl, $locales, $latestPublication, $submissionContext, $vocabSuggestionUrlBase, true);
$metadataEnabled = count($metadataForm->fields);
@@ -336,7 +336,7 @@ public function setupTemplate($request)
$templateMgr->setConstants([
'FORM_METADATA' => FORM_METADATA,
]);
- $state['components'][FORM_METADATA] = $this->getLocalizedForm($metadataForm, $submission, $submissionContext);
+ $state['components'][FORM_METADATA] = $this->getLocalizedForm($metadataForm, $latestPublication, $submissionContext);
$state['publicationFormIds'][] = FORM_METADATA;
}
@@ -373,34 +373,28 @@ protected function getContributorsListPanel(Submission $submission, Context $con
/**
* Get the form configuration data with the correct
- * locale settings based on the submission's locale
+ * locale settings based on the publication's locale
*
- * Uses the submission locale as the primary and
+ * Uses the publication locale as the primary and
* visible locale, and puts that locale first in the
* list of supported locales.
*
* Call this instead of $form->getConfig() to display
- * a form with the correct submission locales
+ * a form with the correct publication locales
*/
- protected function getLocalizedForm(\PKP\components\forms\FormComponent $form, Submission $submission, Context $context): array
+ protected function getLocalizedForm(\PKP\components\forms\FormComponent $form, Publication $publication, Context $context): array
{
$config = $form->getConfig();
- $primaryLocale = $submission->getData('locale');
+ $primaryLocale = $publication->getData('locale');
$config['primaryLocale'] = $primaryLocale;
$config['visibleLocales'] = [$primaryLocale];
- $supportedFormLocales = [];
- foreach ($context->getSupportedSubmissionMetadataLocaleNames() + [$primaryLocale => ""] as $localeKey => $name) {
- $supportedFormLocales[] = [
- 'key' => $localeKey,
- 'label' => (new LocaleMetadata($localeKey))->getDisplayName(null, true),
- ];
- }
-
- usort($supportedFormLocales, fn ($a, $b) => $a['key'] === $primaryLocale ? -1 : 1);
-
- $config['supportedFormLocales'] = $supportedFormLocales;
+ $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])
+ ->toArray();
return $config;
}
diff --git a/pages/workflow/PKPWorkflowHandler.php b/pages/workflow/PKPWorkflowHandler.php
index bcd23323d1b..daa589e5716 100644
--- a/pages/workflow/PKPWorkflowHandler.php
+++ b/pages/workflow/PKPWorkflowHandler.php
@@ -37,7 +37,6 @@
use PKP\core\PKPApplication;
use PKP\core\PKPRequest;
use PKP\db\DAORegistry;
-use PKP\i18n\LocaleMetadata;
use PKP\notification\NotificationDAO;
use PKP\notification\PKPNotification;
use PKP\plugins\PluginRegistry;
@@ -217,12 +216,13 @@ public function index($args, $request)
$genreDao = DAORegistry::getDAO('GenreDAO');
$genres = $genreDao->getByContextId($submission->getData('contextId'))->toArray();
- $locales = $submissionContext->getSupportedSubmissionMetadataLocaleNames() + [$submission->getData('locale') => (new LocaleMetadata($submission->getData('locale')))->getDisplayName(null, false)];
- ksort($locales);
- $locales = array_map(fn (string $locale, string $name) => ['key' => $locale, 'label' => $name], array_keys($locales), $locales);
-
$latestPublication = $submission->getLatestPublication();
+ $locales = collect($submissionContext->getSupportedSubmissionMetadataLocaleNames() + $latestPublication->getLanguageNames())
+ ->map(fn (string $name, string $locale) => ['key' => $locale, 'label' => $name])
+ ->sortBy('key')
+ ->toArray();
+
$submissionApiUrl = $request->getDispatcher()->url($request, Application::ROUTE_API, $submissionContext->getData('urlPath'), 'submissions/' . $submission->getId());
$submissionFileApiUrl = $request->getDispatcher()->url($request, Application::ROUTE_API, $submissionContext->getData('urlPath'), 'submissions/' . $submission->getId() . '/files');
$latestPublicationApiUrl = $request->getDispatcher()->url($request, Application::ROUTE_API, $submissionContext->getData('urlPath'), 'submissions/' . $submission->getId() . '/publications/' . $latestPublication->getId());
@@ -332,8 +332,8 @@ public function index($args, $request)
'components' => [
$contributorsListPanel->id => $contributorsListPanel->getConfig(),
$citationsForm->id => $citationsForm->getConfig(),
- $publicationLicenseForm->id => $this->getLocalizedForm($publicationLicenseForm, $submission, $submissionContext),
- $titleAbstractForm->id => $this->getLocalizedForm($titleAbstractForm, $submission, $submissionContext),
+ $publicationLicenseForm->id => $this->getLocalizedForm($publicationLicenseForm, $latestPublication, $submissionContext),
+ $titleAbstractForm->id => $this->getLocalizedForm($titleAbstractForm, $latestPublication, $submissionContext),
],
'currentPublication' => $currentPublicationProps,
'decisionUrl' => $decisionUrl,
@@ -368,7 +368,7 @@ public function index($args, $request)
];
// Add the metadata form if one or more metadata fields are enabled
- $vocabSuggestionUrlBase = $request->getDispatcher()->url($request, PKPApplication::ROUTE_API, $submissionContext->getData('urlPath'), 'vocabs', null, null, ['vocab' => '__vocab__', 'submissionId' => $submission->getId()]);
+ $vocabSuggestionUrlBase = $request->getDispatcher()->url($request, PKPApplication::ROUTE_API, $submissionContext->getData('urlPath'), 'vocabs', null, null, ['vocab' => '__vocab__', 'publicationId' => $latestPublication->getId()]);
$metadataForm = new PKPMetadataForm($latestPublicationApiUrl, $locales, $latestPublication, $submissionContext, $vocabSuggestionUrlBase, true);
$metadataEnabled = count($metadataForm->fields);
@@ -376,7 +376,7 @@ public function index($args, $request)
$templateMgr->setConstants([
'FORM_METADATA' => FORM_METADATA,
]);
- $state['components'][FORM_METADATA] = $this->getLocalizedForm($metadataForm, $submission, $submissionContext);
+ $state['components'][FORM_METADATA] = $this->getLocalizedForm($metadataForm, $latestPublication, $submissionContext);
$state['publicationFormIds'][] = FORM_METADATA;
}
@@ -403,7 +403,7 @@ public function index($args, $request)
$selectRevisionDecisionForm = new \PKP\components\forms\decision\SelectRevisionDecisionForm();
$selectRevisionRecommendationForm = new \PKP\components\forms\decision\SelectRevisionRecommendationForm();
$state['components'][$selectRevisionDecisionForm->id] = $selectRevisionDecisionForm->getConfig();
- $state['components'][$selectRevisionRecommendationForm->id] = $this->getLocalizedForm($selectRevisionRecommendationForm, $submission, $submissionContext);
+ $state['components'][$selectRevisionRecommendationForm->id] = $this->getLocalizedForm($selectRevisionRecommendationForm, $latestPublication, $submissionContext);
$templateMgr->setConstants([
'FORM_SELECT_REVISION_DECISION' => FORM_SELECT_REVISION_DECISION,
'FORM_SELECT_REVISION_RECOMMENDATION' => FORM_SELECT_REVISION_RECOMMENDATION,
@@ -825,34 +825,28 @@ protected function notificationOptionsByStage($user, $stageId, $contextId)
/**
* Get the form configuration data with the correct
- * locale settings based on the submission's locale
+ * locale settings based on the publication's locale
*
- * Uses the submission locale as the primary and
+ * Uses the publication locale as the primary and
* visible locale, and puts that locale first in the
* list of supported locales.
*
* Call this instead of $form->getConfig() to display
- * a form with the correct submission locales
+ * a form with the correct publication locales
*/
- protected function getLocalizedForm(\PKP\components\forms\FormComponent $form, Submission $submission, Context $context): array
+ protected function getLocalizedForm(\PKP\components\forms\FormComponent $form, Publication $publication, Context $context): array
{
$config = $form->getConfig();
- $primaryLocale = $submission->getData('locale');
+ $primaryLocale = $publication->getData('locale');
$config['primaryLocale'] = $primaryLocale;
$config['visibleLocales'] = [$primaryLocale];
- $supportedFormLocales = [];
- foreach ($context->getSupportedSubmissionMetadataLocaleNames() + [$primaryLocale => ""] as $localeKey => $name) {
- $supportedFormLocales[] = [
- 'key' => $localeKey,
- 'label' => (new LocaleMetadata($localeKey))->getDisplayName(null, true),
- ];
- }
-
- usort($supportedFormLocales, fn ($a, $b) => $a['key'] === $primaryLocale ? -1 : 1);
-
- $config['supportedFormLocales'] = $supportedFormLocales;
+ $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])
+ ->toArray();
return $config;
}
diff --git a/templates/admin/contextSettings.tpl b/templates/admin/contextSettings.tpl
index cdfb4921954..d53cf0008c3 100644
--- a/templates/admin/contextSettings.tpl
+++ b/templates/admin/contextSettings.tpl
@@ -38,8 +38,8 @@
{capture assign=languagesUrl}{url router=\PKP\core\PKPApplication::ROUTE_COMPONENT context=$editContext->getPath() component="grid.settings.languages.ManageLanguageGridHandler" op="fetchGrid" escape=false}{/capture}
{load_url_in_div id="languageGridContainer" url=$languagesUrl}
- {capture assign=languagesUrl}{url router=\PKP\core\PKPApplication::ROUTE_COMPONENT context=$editContext->getPath() component="grid.settings.languages.SubmissionLanguageGridHandler" op="fetchGrid" escape=false}{/capture}
- {load_url_in_div id="submissionLanguageGridContainer" url=$languagesUrl}
+ {capture assign=submissionLanguagesUrl}{url router=\PKP\core\PKPApplication::ROUTE_COMPONENT context=$editContext->getPath() component="grid.settings.languages.SubmissionLanguageGridHandler" op="fetchGrid" escape=false}{/capture}
+ {load_url_in_div id="submissionLanguageGridContainer" url=$submissionLanguagesUrl}
{capture assign=languagesUrl}{url router=\PKP\core\PKPApplication::ROUTE_COMPONENT component="grid.settings.languages.ManageLanguageGridHandler" op="fetchGrid" escape=false}{/capture}
{load_url_in_div id="languageGridContainer" url=$languagesUrl}
- {capture assign=languagesUrl}{url router=\PKP\core\PKPApplication::ROUTE_COMPONENT component="grid.settings.languages.SubmissionLanguageGridHandler" op="fetchGrid" escape=false}{/capture}
- {load_url_in_div id="submissionLanguageGridContainer" url=$languagesUrl}
+ {capture assign=submissionLanguagesUrl}{url router=\PKP\core\PKPApplication::ROUTE_COMPONENT component="grid.settings.languages.SubmissionLanguageGridHandler" op="fetchGrid" escape=false}{/capture}
+ {load_url_in_div id="submissionLanguageGridContainer" url=$submissionLanguagesUrl}