Skip to content

Commit

Permalink
Submission and metadata languages separated from UI and form languages
Browse files Browse the repository at this point in the history
  • Loading branch information
jyhein committed Sep 19, 2023
1 parent b1a84d3 commit efb4abe
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 17 deletions.
4 changes: 2 additions & 2 deletions classes/install/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions classes/publication/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion classes/publication/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion classes/submission/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
5 changes: 4 additions & 1 deletion classes/submission/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
16 changes: 10 additions & 6 deletions controllers/grid/articleGalleys/form/ArticleGalleyForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use APP\template\TemplateManager;
use PKP\form\Form;
use PKP\galley\Galley;
use PKP\i18n\LocaleMetadata;

class ArticleGalleyForm extends Form
{
Expand Down Expand Up @@ -62,17 +63,16 @@ 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,
'locale',
'required',
'editor.issues.galleyLocaleRequired'
),
function ($locale) use ($journal) {
return in_array($locale, $journal->getSupportedSubmissionLocaleNames());
}
fn ($locale) => in_array($locale, $locales)
);
}

Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions cypress/tests/data/10-ApplicationSetup/20-CreateContext.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
5 changes: 3 additions & 2 deletions pages/workflow/WorkflowHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand Down

0 comments on commit efb4abe

Please sign in to comment.