Skip to content

Commit

Permalink
pkp#10500 Expose ChangeSubmissionLanguageMetadataForm via api
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham committed Oct 4, 2024
1 parent d86f5d1 commit 8753c00
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion api/v1/submissions/PKPSubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use PKP\components\forms\publication\PKPPublicationIdentifiersForm;
use PKP\components\forms\publication\PKPPublicationLicenseForm;
use PKP\components\forms\publication\TitleAbstractForm;
use PKP\components\forms\submission\ChangeSubmissionLanguageMetadataForm;
use PKP\context\Context;
use PKP\core\Core;
use PKP\core\PKPApplication;
Expand Down Expand Up @@ -109,7 +110,8 @@ class PKPSubmissionController extends PKPBaseController
'getPublicationMetadataForm',
'getPublicationIdentifierForm',
'getPublicationLicenseForm',
'getPublicationTitleAbstractForm'
'getPublicationTitleAbstractForm',
'getChangeLanguageMetadata'
];

/** @var array Handlers that must be authorized to write to a publication */
Expand Down Expand Up @@ -298,6 +300,7 @@ public function getGroupRoutes(): void
Route::get('metadata', $this->getPublicationMetadataForm(...))->name('submission.publication._components.metadata');
Route::get('reference', $this->getPublicationReferenceForm(...))->name('submission.publication._components.reference');
Route::get('titleAbstract', $this->getPublicationTitleAbstractForm(...))->name('submission.publication._components.titleAbstract');
Route::get('changeLanguageMetadata', $this->getChangeLanguageMetadata(...))->name('submission.publication._components.changeLanguageMetadata');
})->whereNumber(['submissionId', 'publicationId']);
});

Expand Down Expand Up @@ -379,6 +382,7 @@ public function authorize(PKPRequest $request, array &$args, array $roleAssignme
'getPublicationIdentifierForm',
'getPublicationLicenseForm',
'getPublicationTitleAbstractForm',
'getChangeLanguageMetadata'
]
)) {
$this->addPolicy(new SubmissionCompletePolicy($request, $args));
Expand Down Expand Up @@ -1967,6 +1971,36 @@ protected function getPublicationTitleAbstractForm(Request $illuminateRequest):
return response()->json($titleAbstract->getConfig(), Response::HTTP_OK);
}

/**
* Get ChangeSubmissionLanguageMetadata Form component
*/
protected function getChangeLanguageMetadata(Request $illuminateRequest): JsonResponse
{
$request = $this->getRequest();
$data = $this->getSubmissionAndPublicationData($illuminateRequest);

if (isset($data['error'])) {
return response()->json(['error' => $data['error']], $data['status']);
}

$context = $data['context']; /** @var Context $context*/
$submission = $data['submission']; /** @var Submission $submission */
$publication = $data['publication']; /** @var Publication $publication*/
$locales = $this->getPublicationFormLocales($context, $submission);

$changeSubmissionLanguageApiUrl = $request->getDispatcher()->url(
$request,
Application::ROUTE_API,
$context->getData('urlPath'),
"submissions/{$submission->getId()}/publications/{$publication->getId()}/changeLocale"
);

$changeSubmissionLanguageMetadataForm = new ChangeSubmissionLanguageMetadataForm($changeSubmissionLanguageApiUrl, $submission, $publication, $context);
$submissionLocale = $submission->getData('locale');

return response()->json($this->getLocalizedForm($changeSubmissionLanguageMetadataForm, $submissionLocale, $locales), Response::HTTP_OK);
}

/**
* Utility method used to get the metadata locale information for a submission publications and context
*/
Expand Down

0 comments on commit 8753c00

Please sign in to comment.