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 Oct 27, 2023
1 parent 1d3adda commit 8e3067b
Show file tree
Hide file tree
Showing 8 changed files with 19 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
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="PKP\migration\upgrade\v3_5_0\I9425_SeparateUIAndSubmissionLocales"/>
</upgrade>

<!-- update plugin configuration - should be done as the final upgrade task -->
Expand Down
11 changes: 6 additions & 5 deletions pages/workflow/WorkflowHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ 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')
->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 +115,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 8e3067b

Please sign in to comment.