diff --git a/bundle/Controller/ContentEditController.php b/bundle/Controller/ContentEditController.php index 897aa2a5d..f34155c7c 100644 --- a/bundle/Controller/ContentEditController.php +++ b/bundle/Controller/ContentEditController.php @@ -12,8 +12,11 @@ use eZ\Publish\API\Repository\ContentService; use eZ\Publish\API\Repository\ContentTypeService; use eZ\Publish\API\Repository\LocationService; +use eZ\Publish\API\Repository\Values\Content\VersionInfo; +use eZ\Publish\Core\Base\Exceptions\BadStateException; use EzSystems\RepositoryForms\Data\Content\CreateContentDraftData; use EzSystems\RepositoryForms\Data\Mapper\ContentCreateMapper; +use EzSystems\RepositoryForms\Data\Mapper\ContentUpdateMapper; use EzSystems\RepositoryForms\Form\ActionDispatcher\ActionDispatcherInterface; use EzSystems\RepositoryForms\Form\Type\Content\ContentDraftCreateType; use EzSystems\RepositoryForms\Form\Type\Content\ContentEditType; @@ -126,15 +129,56 @@ public function createContentDraftAction($contentId, $fromVersionNo = null, $fro $form->handleRequest($request); if ($form->isValid()) { - $this->contentService->createContentDraft( - $contentInfo, - $this->contentService->loadVersionInfo($contentInfo, $fromVersionNo) - ); + $this->contentActionDispatcher->dispatchFormAction($form, $createContentDraft, $form->getClickedButton()->getName()); + if ($response = $this->contentActionDispatcher->getResponse()) { + return $response; + } } return $this->render('@EzSystemsRepositoryForms/Content/content_create_draft.html.twig', [ 'form' => $form->createView(), - //'languageCode' => $language, + 'pagelayout' => $this->pagelayout, + ]); + } + + /** + * Shows a content draft editing form. + * + * @param int $contentId ContentType id to create + * @param int $versionNo Version number the version should be created from. Defaults to the currently published one. + * @param \Symfony\Component\HttpFoundation\Request $request + * @param string $language Language code to create the version in (eng-GB, ger-DE, ...)) + * + * @return \Symfony\Component\HttpFoundation\Response + * @throws \eZ\Publish\Core\Base\Exceptions\BadStateException If the version isn't editable, or if there is no editable version. + */ + public function editContentDraftAction($contentId, $versionNo = null, Request $request, $language = null) + { + $draft = $this->contentService->loadContent($contentId, [$language], $versionNo); + if ($draft->getVersionInfo()->status !== VersionInfo::STATUS_DRAFT) { + throw new BadStateException('Version status', 'status is not draft'); + } + + $contentUpdate = (new ContentUpdateMapper())->mapToFormData( + $draft, + [ + 'languageCode' => $language, + 'contentType' => $this->contentTypeService->loadContentType($draft->contentInfo->contentTypeId), + ] + ); + $form = $this->createForm(ContentEditType::class, $contentUpdate, ['languageCode' => $language]); + $form->handleRequest($request); + + if ($form->isValid()) { + $this->contentActionDispatcher->dispatchFormAction($form, $contentUpdate, $form->getClickedButton()->getName()); + if ($response = $this->contentActionDispatcher->getResponse()) { + return $response; + } + } + + return $this->render('EzSystemsRepositoryFormsBundle:Content:content_edit.html.twig', [ + 'form' => $form->createView(), + 'languageCode' => $language, 'pagelayout' => $this->pagelayout, ]); } diff --git a/bundle/Resources/config/routing.yml b/bundle/Resources/config/routing.yml index e6e8361ee..dcae871b7 100644 --- a/bundle/Resources/config/routing.yml +++ b/bundle/Resources/config/routing.yml @@ -3,6 +3,12 @@ ez_content_create_no_draft: defaults: _controller: ez_content_edit:createWithoutDraftAction +ez_content_edit: + path: /content/edit/{contentId}/{versionNo}/{language} + defaults: + _controller: ez_content_edit:editContentDraftAction + language: null + ez_content_draft_create: path: /content/create/draft/{contentId}/{fromVersionNo}/{fromLanguage}/{toLanguage} defaults: diff --git a/lib/Data/Content/ContentUpdateData.php b/lib/Data/Content/ContentUpdateData.php new file mode 100644 index 000000000..d75412d48 --- /dev/null +++ b/lib/Data/Content/ContentUpdateData.php @@ -0,0 +1,28 @@ +configureOptions($optionsResolver); $params = $optionsResolver->resolve($params); - $data = new ContentUpdateData(['contentDraft' => $contentDraft, 'contentType' => $params['contentType']]); + $data = new ContentUpdateData(['contentDraft' => $contentDraft]); $fields = $contentDraft->getFieldsByLanguage($params['languageCode']); foreach ($params['contentType']->fieldDefinitions as $fieldDef) { $field = $fields[$fieldDef->identifier];