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 21c991d commit 6c57d82
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 17 deletions.
3 changes: 2 additions & 1 deletion classes/publication/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function validate($publication, array $props, Submission $submission, Con
{
$errors = parent::validate($publication, $props, $submission, $context);

$allowedLocales = $context->getSupportedSubmissionLocales();
$primaryLocale = $submission->getLocale();
$allowedLocales = array_values(array_unique(array_merge($context->getSupportedSubmissionMetadataLocales(), $publication?->getLanguages() ?? [$primaryLocale])));

// Ensure that the specified section exists
$section = null;
Expand Down Expand Up @@ -189,6 +189,7 @@ public function relate(Publication $publication, int $relationStatus, ?string $v
* Publication::canAuthorPublish.
*
* @deprecated 3.4
*
* @hook Publication::canAuthorPublish [[$this]]
*/
public function canCurrentUserPublish(int $submissionId, ?User $user = null): bool
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 @@ -49,7 +49,9 @@ protected function mapByProperties(array $props, Publication $publication, bool
);
}

$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
3 changes: 2 additions & 1 deletion classes/submission/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function validateSubmit(Submission $submission, Context $context): array
$abstracts = $publication->getData('abstract');
if ($abstracts) {
$abstractErrors = [];
foreach ($context->getSupportedSubmissionLocales() as $localeKey) {
$allowedLocales = $publication->getLanguages($context->getSupportedSubmissionMetadataLocales());
foreach ($allowedLocales as $localeKey) {
$abstract = $publication->getData('abstract', $localeKey);
$wordCount = $abstract ? PKPString::getWordCount($abstract) : 0;
if ($wordCount > $section->getAbstractWordCount()) {
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 @@ -35,7 +35,13 @@ protected function mapByProperties(array $props, Submission $submission): array
);
}

$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
16 changes: 9 additions & 7 deletions controllers/grid/preprintGalleys/form/PreprintGalleyForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use APP\core\Request;
use APP\facades\Repo;
use APP\publication\Publication;
use APP\server\Server;
use APP\submission\Submission;
use APP\template\TemplateManager;
use PKP\form\Form;
Expand Down Expand Up @@ -65,21 +64,21 @@ public function __construct($request, $submission, $publication, $preprintGalley
$this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this));

// Ensure a locale is provided and valid
$server = $request->getServer();
$locales = $request->getServer()->getSupportedSubmissionMetadataLocales() + $publication->getLanguages();
$this->addCheck(
new \PKP\form\validation\FormValidator(
$this,
'locale',
'required',
'validator.required',
new class ($server) extends Validator {
public function __construct(private Server $server)
new class ($locales) extends Validator {
public function __construct(private array $locales)
{
}

public function isValid($locale): bool
{
return in_array($locale, $this->server->getSupportedSubmissionLocales());
return in_array($locale, $this->locales);
}
}
)
Expand All @@ -104,9 +103,12 @@ public function fetch($request, $template = null, $display = false)
'supportsDependentFiles' => $preprintGalleyFile ? Repo::submissionFile()->supportsDependentFiles($preprintGalleyFile) : null,
]);
}
$context = $request->getContext();

$supportedLocales = $request->getContext()->getSupportedSubmissionMetadataLocaleNames() + $this->_publication->getLanguageNames();
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
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,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
10 changes: 6 additions & 4 deletions pages/workflow/WorkflowHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ public function setupIndex($request)
$submissionContext = Services::get('context')->get($submission->getContextId());
}

$locales = $submissionContext->getSupportedSubmissionLocaleNames();
$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')
->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');
$relatePublicationApiUrl = $request->getDispatcher()->url($request, Application::ROUTE_API, $submissionContext->getPath(), 'submissions/' . $submission->getId() . '/publications/' . $latestPublication->getId()) . '/relate';
Expand Down Expand Up @@ -117,7 +119,7 @@ public function setupIndex($request)
}
}
}
$components[FORM_ISSUE_ENTRY] = $issueEntryForm->getConfig();
$components[FORM_ISSUE_ENTRY] = $this->getLocalizedForm($issueEntryForm, $latestPublication, $submissionContext);
$components[FORM_ID_RELATION] = $relationForm->getConfig();

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

0 comments on commit 6c57d82

Please sign in to comment.