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 31, 2023
1 parent 528f732 commit f7f6525
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 19 deletions.
9 changes: 4 additions & 5 deletions api/v1/_submissions/BackendSubmissionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ public function addToCatalog(Request $illuminateRequest): JsonResponse
], Response::HTTP_BAD_REQUEST);
}

$primaryLocale = $this->getRequest()->getContext()->getPrimaryLocale();
$allowedLocales = $this->getRequest()->getContext()->getSupportedFormLocales();
$submissionLocale = $submission->getData('locale');
$supportedMetadataLocales = $this->getRequest()->getContext()->getSupportedSubmissionMetadataLocales();

$validPublications = [];
foreach ($submissionIds as $submissionId) {
Expand All @@ -193,9 +193,8 @@ public function addToCatalog(Request $illuminateRequest): JsonResponse
if ($publication->getData('status') === Submission::STATUS_PUBLISHED) {
continue;
}

$errors = Repo::publication()->validatePublish($publication, $submission, $allowedLocales, $primaryLocale);

$allowedLocales = $publication->getLanguages($supportedMetadataLocales);
$errors = Repo::publication()->validatePublish($publication, $submission, $allowedLocales, $submissionLocale);
if (!empty($errors)) {
return response()->json($errors, Response::HTTP_BAD_REQUEST);
}
Expand Down
4 changes: 3 additions & 1 deletion api/v1/vocabs/VocabController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use APP\codelist\ONIXCodelistItemDAO;
use APP\core\Application;
use APP\facades\Repo;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
Expand Down Expand Up @@ -50,8 +51,9 @@ public function getMany(Request $illuminateRequest): JsonResponse
$locale = $requestParams['locale'] ?? Locale::getLocale();
$term = $requestParams['term'] ?? null;
$codeList = (int) ($requestParams['codeList'] ?? static::LANGUAGE_CODE_LIST);
$locales = array_merge($context->getSupportedSubmissionMetadataLocales(), isset($requestParams['publicationId']) ? Repo::publication()->get((int) $requestParams['publicationId'])?->getLanguages() ?? [] : []);

if (!in_array($locale, $context->getData('supportedSubmissionLocales'))) {
if (!in_array($locale, $locales)) {
return response()->json([
'error' => __('api.vocabs.400.localeNotSupported', ['locale' => $locale]),
], Response::HTTP_BAD_REQUEST);
Expand Down
7 changes: 4 additions & 3 deletions classes/components/listPanels/CatalogListPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ public function getConfig()
'submissions'
);

$locales = $context->getSupportedFormLocaleNames();
$locales = array_map(fn (string $locale, string $name) => ['key' => $locale, 'label' => $name], array_keys($locales), $locales);
$locales = collect($context->getSupportedSubmissionMetadataLocaleNames())
->map(fn (string $locale, string $name) => ['key' => $locale, 'label' => $name])
->values()
->toArray();
$addEntryForm = new \APP\components\forms\catalog\AddEntryForm($addEntryApiUrl, $searchSubmissionsApiUrl, $locales);
$config['addEntryForm'] = $addEntryForm->getConfig();

Expand All @@ -150,7 +152,6 @@ public function getConfig()
'ASSOC_TYPE_SERIES' => Application::ASSOC_TYPE_SERIES,
]);


return $config;
}
}
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 'presses';
}
protected function getContextSettingsTable(): string
{
return 'press_settings';
}
protected function getContextIdColumn(): string
{
return 'press_id';
}
}
2 changes: 1 addition & 1 deletion classes/publication/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function add(Publication $publication): int
$submissionContext = Services::get('context')->get($submission->getData('contextId'));
}

$supportedLocales = $submissionContext->getSupportedSubmissionLocales();
$supportedLocales = $publication->getLanguages($submissionContext->getSupportedSubmissionMetadataLocales());
foreach ($supportedLocales as $localeKey) {
if (!array_key_exists($localeKey, $publication->getData('coverImage'))) {
continue;
Expand Down
4 changes: 3 additions & 1 deletion classes/publication/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ function ($publicationFormat) use ($submissionFiles, $genres) {
);
}

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

Expand Down
8 changes: 7 additions & 1 deletion classes/submission/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ protected function mapByProperties(array $props, Submission $submission): array
$output['newRelease'] = $newReleaseDao->getNewReleaseAll($submission->getId());
}

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

Expand Down
3 changes: 2 additions & 1 deletion controllers/grid/catalogEntry/form/PublicationFormatForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class PublicationFormatForm extends Form
*/
public function __construct($monograph, $publicationFormat, $publication)
{
parent::__construct('controllers/grid/catalogEntry/form/formatForm.tpl');
$localeNames = Application::get()->getRequest()->getContext()->getSupportedSubmissionMetadataLocaleNames() + $publication->getLanguageNames();
parent::__construct('controllers/grid/catalogEntry/form/formatForm.tpl', true, $publication->getData('locale'), $localeNames);
$this->setMonograph($monograph);
$this->setPublicationFormat($publicationFormat);
$this->setPublication($publication);
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']);
Expand Down
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
<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\I9262_Highlights"/>
<migration class="APP\migration\upgrade\v3_5_0\I9425_SeparateUIAndSubmissionLocales"/>
</upgrade>

<!-- Update plugin configuration - should be done as the final upgrade task -->
Expand Down
12 changes: 8 additions & 4 deletions pages/workflow/WorkflowHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ public function setupIndex($request)
$submissionContext = Services::get('context')->get($submission->getContextId());
}

$locales = $submissionContext->getSupportedFormLocaleNames();
$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')
->values()
->toArray();

$submissionApiUrl = $request->getDispatcher()->url($request, PKPApplication::ROUTE_API, $submissionContext->getData('urlPath'), 'submissions/' . $submission->getId());
$latestPublicationApiUrl = $request->getDispatcher()->url($request, PKPApplication::ROUTE_API, $submissionContext->getData('urlPath'), 'submissions/' . $submission->getId() . '/publications/' . $latestPublication->getId());
$temporaryFileApiUrl = $request->getDispatcher()->url($request, PKPApplication::ROUTE_API, $submissionContext->getData('urlPath'), 'temporaryFiles');
Expand Down Expand Up @@ -156,9 +160,9 @@ public function setupIndex($request)

$components = $templateMgr->getState('components');
$components[FORM_AUDIENCE] = $audienceForm->getConfig();
$components[FORM_CATALOG_ENTRY] = $catalogEntryForm->getConfig();
$components[FORM_CATALOG_ENTRY] = $this->getLocalizedForm($catalogEntryForm, $latestPublication, $submissionContext);
$components[FORM_PUBLICATION_DATES] = $publicationDatesForm->getConfig();
$components[$publicationLicenseForm->id] = $publicationLicenseForm->getConfig();
$components[$publicationLicenseForm->id] = $this->getLocalizedForm($publicationLicenseForm, $latestPublication, $submissionContext);

$publicationFormIds = $templateMgr->getState('publicationFormIds');
$publicationFormIds[] = FORM_CATALOG_ENTRY;
Expand Down

0 comments on commit f7f6525

Please sign in to comment.