From 6c57d826130d347eeb74f09f0c57bc080993a9cf Mon Sep 17 00:00:00 2001 From: jyhein <124268211+jyhein@users.noreply.github.com> Date: Fri, 27 Oct 2023 12:00:43 +0300 Subject: [PATCH] pkp/pkp-lib#9425 Make submission language selection and metadata forms independent from website language settings --- classes/publication/Repository.php | 3 ++- classes/publication/maps/Schema.php | 4 +++- classes/submission/Repository.php | 3 ++- classes/submission/maps/Schema.php | 8 +++++++- .../preprintGalleys/form/PreprintGalleyForm.php | 16 +++++++++------- .../10-ApplicationSetup/20-CreateContext.cy.js | 9 +++++++-- dbscripts/xml/upgrade.xml | 1 + pages/workflow/WorkflowHandler.php | 10 ++++++---- 8 files changed, 37 insertions(+), 17 deletions(-) diff --git a/classes/publication/Repository.php b/classes/publication/Repository.php index 16c6132d97..b90d339319 100644 --- a/classes/publication/Repository.php +++ b/classes/publication/Repository.php @@ -42,8 +42,8 @@ public function validate($publication, array $props, Submission $submission, Con { $errors = parent::validate($publication, $props, $submission, $context); - $allowedLocales = $context->getSupportedSubmissionLocales(); $primaryLocale = $submission->getLocale(); + $allowedLocales = array_values(array_unique(array_merge($context->getSupportedSubmissionMetadataLocales(), $publication?->getLanguages() ?? [$primaryLocale]))); // Ensure that the specified section exists $section = null; @@ -189,6 +189,7 @@ public function relate(Publication $publication, int $relationStatus, ?string $v * Publication::canAuthorPublish. * * @deprecated 3.4 + * * @hook Publication::canAuthorPublish [[$this]] */ public function canCurrentUserPublish(int $submissionId, ?User $user = null): bool diff --git a/classes/publication/maps/Schema.php b/classes/publication/maps/Schema.php index 62841b8c5a..7c8e791bbe 100644 --- a/classes/publication/maps/Schema.php +++ b/classes/publication/maps/Schema.php @@ -49,7 +49,9 @@ protected function mapByProperties(array $props, Publication $publication, bool ); } - $output = $this->schemaService->addMissingMultilingualValues(PKPSchemaService::SCHEMA_PUBLICATION, $output, $this->context->getSupportedSubmissionLocales()); + $locales = $publication->getLanguages($this->context->getSupportedSubmissionMetadataLocales()); + + $output = $this->schemaService->addMissingMultilingualValues(PKPSchemaService::SCHEMA_PUBLICATION, $output, $locales); ksort($output); diff --git a/classes/submission/Repository.php b/classes/submission/Repository.php index 635c03f739..632a32bf5e 100644 --- a/classes/submission/Repository.php +++ b/classes/submission/Repository.php @@ -50,7 +50,8 @@ public function validateSubmit(Submission $submission, Context $context): array $abstracts = $publication->getData('abstract'); if ($abstracts) { $abstractErrors = []; - foreach ($context->getSupportedSubmissionLocales() as $localeKey) { + $allowedLocales = $publication->getLanguages($context->getSupportedSubmissionMetadataLocales()); + foreach ($allowedLocales as $localeKey) { $abstract = $publication->getData('abstract', $localeKey); $wordCount = $abstract ? PKPString::getWordCount($abstract) : 0; if ($wordCount > $section->getAbstractWordCount()) { diff --git a/classes/submission/maps/Schema.php b/classes/submission/maps/Schema.php index afb79640e5..2057dd5843 100644 --- a/classes/submission/maps/Schema.php +++ b/classes/submission/maps/Schema.php @@ -35,7 +35,13 @@ protected function mapByProperties(array $props, Submission $submission): array ); } - $output = $this->schemaService->addMissingMultilingualValues($this->schemaService::SCHEMA_SUBMISSION, $output, $this->context->getSupportedSubmissionLocales()); + $locales = $this->context->getSupportedSubmissionMetaDataLocales(); + + if (!in_array($primaryLocale = $submission->getData('locale'), $locales)) { + $locales[] = $primaryLocale; + } + + $output = $this->schemaService->addMissingMultilingualValues($this->schemaService::SCHEMA_SUBMISSION, $output, $locales); ksort($output); diff --git a/controllers/grid/preprintGalleys/form/PreprintGalleyForm.php b/controllers/grid/preprintGalleys/form/PreprintGalleyForm.php index 58f12c7ddf..fdb9587787 100644 --- a/controllers/grid/preprintGalleys/form/PreprintGalleyForm.php +++ b/controllers/grid/preprintGalleys/form/PreprintGalleyForm.php @@ -21,7 +21,6 @@ use APP\core\Request; use APP\facades\Repo; use APP\publication\Publication; -use APP\server\Server; use APP\submission\Submission; use APP\template\TemplateManager; use PKP\form\Form; @@ -65,21 +64,21 @@ public function __construct($request, $submission, $publication, $preprintGalley $this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this)); // Ensure a locale is provided and valid - $server = $request->getServer(); + $locales = $request->getServer()->getSupportedSubmissionMetadataLocales() + $publication->getLanguages(); $this->addCheck( new \PKP\form\validation\FormValidator( $this, 'locale', 'required', 'validator.required', - new class ($server) extends Validator { - public function __construct(private Server $server) + new class ($locales) extends Validator { + public function __construct(private array $locales) { } public function isValid($locale): bool { - return in_array($locale, $this->server->getSupportedSubmissionLocales()); + return in_array($locale, $this->locales); } } ) @@ -104,9 +103,12 @@ public function fetch($request, $template = null, $display = false) 'supportsDependentFiles' => $preprintGalleyFile ? Repo::submissionFile()->supportsDependentFiles($preprintGalleyFile) : null, ]); } - $context = $request->getContext(); + + $supportedLocales = $request->getContext()->getSupportedSubmissionMetadataLocaleNames() + $this->_publication->getLanguageNames(); + ksort($supportedLocales); + $templateMgr->assign([ - 'supportedLocales' => $context->getSupportedSubmissionLocaleNames(), + 'supportedLocales' => $supportedLocales, 'submissionId' => $this->_submission->getId(), 'publicationId' => $this->_publication->getId(), 'formDisabled' => !$this->_isEditable diff --git a/cypress/tests/data/10-ApplicationSetup/20-CreateContext.cy.js b/cypress/tests/data/10-ApplicationSetup/20-CreateContext.cy.js index ea053bfdb1..dde4dc4eca 100644 --- a/cypress/tests/data/10-ApplicationSetup/20-CreateContext.cy.js +++ b/cypress/tests/data/10-ApplicationSetup/20-CreateContext.cy.js @@ -70,8 +70,13 @@ describe('Data suite tests', function() { cy.get('#appearance [role="status"]').contains('Saved'); cy.get('button[id="languages-button"]').click(); - cy.get('input[id^=select-cell-fr_CA-submissionLocale]').click(); - cy.contains('Locale settings saved.'); + cy.get('input[id^="select-cell-fr_CA-formLocale"]').click(); + cy.get('a[id^=component-grid-settings-languages-submissionlanguagegrid-addLanguageModal-button]').click(); + cy.get('#locale-fr_CA').should('exist').click(); + cy.get('#addLanguageForm button[name="submitFormButton"]').click(); + cy.contains('Submission locales updated.').should('exist'); + cy.get('input[id^="select-cell-fr_CA-submissionLocale"]').click(); + cy.get('input[id^="select-cell-fr_CA-submissionMetadataLocale"]').should('be.checked'); cy.get('button[id="indexing-button"]').click(); cy.get('input[name="searchDescription-en"]').type(Cypress.env('contextDescriptions')['en'], {delay: 0}); diff --git a/dbscripts/xml/upgrade.xml b/dbscripts/xml/upgrade.xml index a1e4ef4407..95b56a37f4 100644 --- a/dbscripts/xml/upgrade.xml +++ b/dbscripts/xml/upgrade.xml @@ -110,6 +110,7 @@ + diff --git a/pages/workflow/WorkflowHandler.php b/pages/workflow/WorkflowHandler.php index feaa172d4a..358693b25e 100644 --- a/pages/workflow/WorkflowHandler.php +++ b/pages/workflow/WorkflowHandler.php @@ -73,11 +73,13 @@ public function setupIndex($request) $submissionContext = Services::get('context')->get($submission->getContextId()); } - $locales = $submissionContext->getSupportedSubmissionLocaleNames(); - $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(); + $latestPublicationApiUrl = $request->getDispatcher()->url($request, Application::ROUTE_API, $submissionContext->getPath(), 'submissions/' . $submission->getId() . '/publications/' . $latestPublication->getId()); $temporaryFileApiUrl = $request->getDispatcher()->url($request, Application::ROUTE_API, $submissionContext->getPath(), 'temporaryFiles'); $relatePublicationApiUrl = $request->getDispatcher()->url($request, Application::ROUTE_API, $submissionContext->getPath(), 'submissions/' . $submission->getId() . '/publications/' . $latestPublication->getId()) . '/relate'; @@ -117,7 +119,7 @@ public function setupIndex($request) } } } - $components[FORM_ISSUE_ENTRY] = $issueEntryForm->getConfig(); + $components[FORM_ISSUE_ENTRY] = $this->getLocalizedForm($issueEntryForm, $latestPublication, $submissionContext); $components[FORM_ID_RELATION] = $relationForm->getConfig(); $publicationFormIds = $templateMgr->getState('publicationFormIds');