From efb4abea93d9e9c0cc78bd36752e0fe2965971ce Mon Sep 17 00:00:00 2001 From: jyhein <124268211+jyhein@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:25:36 +0300 Subject: [PATCH] Submission and metadata languages separated from UI and form languages --- classes/install/Upgrade.php | 4 ++-- classes/publication/Repository.php | 5 +++-- classes/publication/maps/Schema.php | 5 ++++- classes/submission/Repository.php | 4 +++- classes/submission/maps/Schema.php | 5 ++++- .../articleGalleys/form/ArticleGalleyForm.php | 16 ++++++++++------ .../10-ApplicationSetup/20-CreateContext.cy.js | 9 +++++++-- pages/workflow/WorkflowHandler.php | 5 +++-- 8 files changed, 36 insertions(+), 17 deletions(-) diff --git a/classes/install/Upgrade.php b/classes/install/Upgrade.php index 13b5eeaba71..93eeec7f20c 100644 --- a/classes/install/Upgrade.php +++ b/classes/install/Upgrade.php @@ -319,8 +319,8 @@ public function getSetting($journalId, $name, $locale = null) // journal_settings // Consider array setting values from the setting names: - // supportedFormLocales, supportedLocales, supportedSubmissionLocales - $settingNames = "('supportedFormLocales', 'supportedLocales', 'supportedSubmissionLocales')"; + // supportedFormLocales, supportedLocales, supportedAddedSubmissionLocales, supportedSubmissionLocales, supportedDefaultSubmissionLocale, supportedSubmissionMetadataLocales + $settingNames = "('supportedFormLocales', 'supportedLocales', 'supportedAddedSubmissionLocales', 'supportedSubmissionLocales', 'supportedDefaultSubmissionLocale', 'supportedSubmissionMetadataLocales')"; // As a precaution use $oldLocaleStringLength, to exclude that the text contain the old locale string $settingValueResult = $journalSettingsDao->retrieve('SELECT * FROM journal_settings WHERE setting_name IN ' . $settingNames . ' AND setting_value LIKE ? AND setting_type = \'object\'', ['%' . $oldLocaleStringLength . ':"' . $oldLocale . '%']); foreach ($settingValueResult as $row) { diff --git a/classes/publication/Repository.php b/classes/publication/Repository.php index b9ba4569ed6..e6efeec3b58 100644 --- a/classes/publication/Repository.php +++ b/classes/publication/Repository.php @@ -41,8 +41,9 @@ public function validate($publication, array $props, Submission $submission, Con { $errors = parent::validate($publication, $props, $submission, $context); - $allowedLocales = $context->getSupportedSubmissionLocales(); - $primaryLocale = $submission->getLocale(); + $primaryLocale = $submission->getData('locale'); + $allowedLocales = $context->getSupportedSubmissionMetadataLocales(); + in_array($primaryLocale, $allowedLocales) || array_push($allowedLocales, $primaryLocale); // Ensure that the specified section exists $section = null; diff --git a/classes/publication/maps/Schema.php b/classes/publication/maps/Schema.php index e01c6337286..f633eee37f5 100644 --- a/classes/publication/maps/Schema.php +++ b/classes/publication/maps/Schema.php @@ -49,7 +49,10 @@ protected function mapByProperties(array $props, Publication $publication, bool ); } - $output = $this->schemaService->addMissingMultilingualValues(PKPSchemaService::SCHEMA_PUBLICATION, $output, $this->context->getSupportedSubmissionLocales()); + $locales = $this->context->getSupportedSubmissionMetadataLocales(); + in_array($primaryLocale = $this->submission->getData('locale'), $locales) || array_push($locales, $primaryLocale); + + $output = $this->schemaService->addMissingMultilingualValues(PKPSchemaService::SCHEMA_PUBLICATION, $output, $locales); ksort($output); diff --git a/classes/submission/Repository.php b/classes/submission/Repository.php index 579c0c9a536..682fdb74bc3 100644 --- a/classes/submission/Repository.php +++ b/classes/submission/Repository.php @@ -80,7 +80,9 @@ public function validateSubmit(Submission $submission, Context $context): array $abstracts = $publication->getData('abstract'); if ($abstracts) { $abstractErrors = []; - foreach ($context->getSupportedSubmissionLocales() as $localeKey) { + $allowedLocales = $context->getSupportedSubmissionMetadataLocales(); + in_array($locale, $allowedLocales) || array_push($allowedLocales, $locale); + 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 272fda89697..72601a999b1 100644 --- a/classes/submission/maps/Schema.php +++ b/classes/submission/maps/Schema.php @@ -36,7 +36,10 @@ protected function mapByProperties(array $props, Submission $submission): array ); } - $output = $this->schemaService->addMissingMultilingualValues($this->schemaService::SCHEMA_SUBMISSION, $output, $this->context->getSupportedSubmissionLocales()); + $locales = $this->context->getSupportedSubmissionMetaDataLocales(); + in_array($primaryLocale = $submission->getData('locale'), $locales) || array_push($locales, $primaryLocale); + + $output = $this->schemaService->addMissingMultilingualValues($this->schemaService::SCHEMA_SUBMISSION, $output, $locales); ksort($output); diff --git a/controllers/grid/articleGalleys/form/ArticleGalleyForm.php b/controllers/grid/articleGalleys/form/ArticleGalleyForm.php index 0ad5450ca89..3aebab4ca76 100644 --- a/controllers/grid/articleGalleys/form/ArticleGalleyForm.php +++ b/controllers/grid/articleGalleys/form/ArticleGalleyForm.php @@ -25,6 +25,7 @@ use APP\template\TemplateManager; use PKP\form\Form; use PKP\galley\Galley; +use PKP\i18n\LocaleMetadata; class ArticleGalleyForm extends Form { @@ -62,7 +63,8 @@ public function __construct($request, $submission, $publication, $articleGalley $this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this)); // Ensure a locale is provided and valid - $journal = $request->getJournal(); + $submissionLocale = $submission->getData('locale'); + $locales = $request->getJournal()->getSupportedSubmissionMetadataLocaleNames() + [$submissionLocale => (new LocaleMetadata($submissionLocale))->getDisplayName(null, false)]; $this->addCheck( new \PKP\form\validation\FormValidator( $this, @@ -70,9 +72,7 @@ public function __construct($request, $submission, $publication, $articleGalley 'required', 'editor.issues.galleyLocaleRequired' ), - function ($locale) use ($journal) { - return in_array($locale, $journal->getSupportedSubmissionLocaleNames()); - } + fn ($locale) => in_array($locale, $locales) ); } @@ -93,9 +93,13 @@ public function fetch($request, $template = null, $display = false) 'supportsDependentFiles' => $articleGalleyFile ? Repo::submissionFile()->supportsDependentFiles($articleGalleyFile) : null, ]); } - $context = $request->getContext(); + + $submissionLocale = $this->_submission->getData('locale'); + $supportedLocales = $request->getContext()->getSupportedSubmissionMetadataLocaleNames() + [$submissionLocale => (new LocaleMetadata($submissionLocale))->getDisplayName(null, false)]; + 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 feac3e8ca6d..4d45190b0fb 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/pages/workflow/WorkflowHandler.php b/pages/workflow/WorkflowHandler.php index 6b2efb910e4..2e55cb9de8e 100644 --- a/pages/workflow/WorkflowHandler.php +++ b/pages/workflow/WorkflowHandler.php @@ -85,8 +85,9 @@ public function setupIndex($request) $submissionContext = Services::get('context')->get($submission->getContextId()); } - $locales = $submissionContext->getSupportedSubmissionLocaleNames(); + $locales = $submissionContext->getSupportedSubmissionMetadataLocaleNames() + [$submission->getData('locale') => (new \PKP\i18n\LocaleMetadata($submission->getData('locale')))->getDisplayName(null, false)]; $locales = array_map(fn (string $locale, string $name) => ['key' => $locale, 'label' => $name], array_keys($locales), $locales); + ksort($locales); $latestPublication = $submission->getLatestPublication(); @@ -113,7 +114,7 @@ class_exists(\APP\components\forms\publication\AssignToIssueForm::class); // For ]); $components = $templateMgr->getState('components'); - $components[FORM_ISSUE_ENTRY] = $issueEntryForm->getConfig(); + $components[FORM_ISSUE_ENTRY] = $this->getLocalizedForm($issueEntryForm, $submission, $submissionContext); // Add payments form if enabled $paymentManager = Application::getPaymentManager($submissionContext);