Skip to content

Commit

Permalink
pkp/pkp-lib#9425 Make submission language selection and metadata form…
Browse files Browse the repository at this point in the history
…s independent from website language settings
  • Loading branch information
jyhein committed Nov 14, 2023
1 parent 251d376 commit b96a056
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 20 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, supportedAddedSubmissionLocales, supportedSubmissionLocales, supportedDefaultSubmissionLocale, supportedSubmissionMetadataLocales
$settingNames = "('supportedFormLocales', 'supportedLocales', 'supportedAddedSubmissionLocales', 'supportedSubmissionLocales', 'supportedDefaultSubmissionLocale', 'supportedSubmissionMetadataLocales')";
// supportedFormLocales, supportedLocales, supportedSubmissionLocales
$settingNames = "('supportedFormLocales', 'supportedLocales', 'supportedSubmissionLocales')";
// 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* @file classes/migration/upgrade/v3_5_0/I9425_SeparateUIAndSubmissionLocales.php
*
* 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 I9425_SeparateUIAndSubmissionLocales
*
* @brief pkp/pkp-lib#9425 Make submission language selection and metadata forms independent from website language settings
*/

namespace APP\migration\upgrade\v3_5_0;

class I9425_SeparateUIAndSubmissionLocales extends \PKP\migration\upgrade\v3_5_0\I9425_SeparateUIAndSubmissionLocales
{
protected function getContextTable(): string
{
return 'journals';
}
protected function getContextSettingsTable(): string
{
return 'journal_settings';
}
protected function getContextIdColumn(): string
{
return 'journal_id';
}
}
3 changes: 1 addition & 2 deletions classes/publication/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public function validate($publication, array $props, Submission $submission, Con
$errors = parent::validate($publication, $props, $submission, $context);

$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])));

// Ensure that the specified section exists
$section = null;
Expand Down
3 changes: 1 addition & 2 deletions classes/publication/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ protected function mapByProperties(array $props, Publication $publication, bool
);
}

$locales = $this->context->getSupportedSubmissionMetadataLocales();
in_array($primaryLocale = $this->submission->getData('locale'), $locales) || array_push($locales, $primaryLocale);
$locales = $publication->getLanguages($this->context->getSupportedSubmissionMetadataLocales());

$output = $this->schemaService->addMissingMultilingualValues(PKPSchemaService::SCHEMA_PUBLICATION, $output, $locales);

Expand Down
3 changes: 1 addition & 2 deletions classes/submission/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public function validateSubmit(Submission $submission, Context $context): array
$abstracts = $publication->getData('abstract');
if ($abstracts) {
$abstractErrors = [];
$allowedLocales = $context->getSupportedSubmissionMetadataLocales();
in_array($locale, $allowedLocales) || array_push($allowedLocales, $locale);
$allowedLocales = $publication->getLanguages($context->getSupportedSubmissionMetadataLocales());
foreach ($allowedLocales as $localeKey) {
$abstract = $publication->getData('abstract', $localeKey);
$wordCount = $abstract ? PKPString::getWordCount($abstract) : 0;
Expand Down
7 changes: 5 additions & 2 deletions classes/submission/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ protected function mapByProperties(array $props, Submission $submission): array
);
}

$locales = $this->context->getSupportedSubmissionMetaDataLocales();
in_array($primaryLocale = $submission->getData('locale'), $locales) || array_push($locales, $primaryLocale);
$locales = $this->context->getSupportedSubmissionMetadataLocales();

if (!in_array($primaryLocale = $submission->getData('locale'), $locales)) {
$locales[] = $primaryLocale;
}

$output = $this->schemaService->addMissingMultilingualValues($this->schemaService::SCHEMA_SUBMISSION, $output, $locales);

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

class ArticleGalleyForm extends Form
{
Expand Down Expand Up @@ -63,8 +62,7 @@ public function __construct($request, $submission, $publication, $articleGalley
$this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this));

// Ensure a locale is provided and valid
$submissionLocale = $submission->getData('locale');
$locales = $request->getJournal()->getSupportedSubmissionMetadataLocaleNames() + [$submissionLocale => (new LocaleMetadata($submissionLocale))->getDisplayName(null, false)];
$locales = $request->getJournal()->getSupportedSubmissionMetadataLocaleNames() + $publication->getLanguageNames();
$this->addCheck(
new \PKP\form\validation\FormValidator(
$this,
Expand Down Expand Up @@ -94,8 +92,7 @@ public function fetch($request, $template = null, $display = false)
]);
}

$submissionLocale = $this->_submission->getData('locale');
$supportedLocales = $request->getContext()->getSupportedSubmissionMetadataLocaleNames() + [$submissionLocale => (new LocaleMetadata($submissionLocale))->getDisplayName(null, false)];
$supportedLocales = $request->getContext()->getSupportedSubmissionMetadataLocaleNames() + $this->_publication->getLanguageNames();
ksort($supportedLocales);

$templateMgr->assign([
Expand Down
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
<upgrade minversion="3.4.0.0" maxversion="3.4.9.9">
<migration class="PKP\migration\upgrade\v3_5_0\I9197_MigrateAccessKeys"/>
<migration class="PKP\migration\upgrade\v3_5_0\I9262_Highlights"/>
<migration class="APP\migration\upgrade\v3_5_0\I9425_SeparateUIAndSubmissionLocales"/>
</upgrade>

<upgrade minversion="3.1.0.0" maxversion="3.4.9.9">
Expand Down
12 changes: 7 additions & 5 deletions pages/workflow/WorkflowHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ public function setupIndex($request)
$submissionContext = Services::get('context')->get($submission->getContextId());
}

$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();

$locales = collect($submissionContext->getSupportedSubmissionMetadataLocaleNames() + $latestPublication->getLanguageNames())
->map(fn (string $name, string $locale) => ['key' => $locale, 'label' => $name])
->sortBy('key')
->values()
->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');
$issueApiUrl = $request->getDispatcher()->url($request, Application::ROUTE_API, $submissionContext->getData('urlPath'), 'issues/__issueId__');
Expand All @@ -114,7 +116,7 @@ class_exists(\APP\components\forms\publication\AssignToIssueForm::class); // For
]);

$components = $templateMgr->getState('components');
$components[FORM_ISSUE_ENTRY] = $this->getLocalizedForm($issueEntryForm, $submission, $submissionContext);
$components[FORM_ISSUE_ENTRY] = $this->getLocalizedForm($issueEntryForm, $latestPublication, $submissionContext);

// Add payments form if enabled
$paymentManager = Application::getPaymentManager($submissionContext);
Expand Down

0 comments on commit b96a056

Please sign in to comment.