From cffe8bd20a31dbdfa1210fe34b17256c48bcaadc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Thu, 14 Oct 2021 16:53:48 +0200 Subject: [PATCH] IBX-1260: As a Developer, I want to extend Content Type Create/Update views --- .../Controller/ContentTypeController.php | 34 +++++--- src/lib/View/ContentTypeCreateView.php | 68 +++++++++++++++ src/lib/View/ContentTypeEditView.php | 83 +++++++++++++++++++ 3 files changed, 172 insertions(+), 13 deletions(-) create mode 100644 src/lib/View/ContentTypeCreateView.php create mode 100644 src/lib/View/ContentTypeEditView.php diff --git a/src/bundle/Controller/ContentTypeController.php b/src/bundle/Controller/ContentTypeController.php index eac7c1ab8b..2445fc74a7 100644 --- a/src/bundle/Controller/ContentTypeController.php +++ b/src/bundle/Controller/ContentTypeController.php @@ -34,6 +34,8 @@ use EzSystems\EzPlatformAdminUi\Tab\ContentType\TranslationsTab; use EzSystems\EzPlatformContentForms\Form\ActionDispatcher\ActionDispatcherInterface; use Ibexa\AdminUi\UI\Module\FieldTypeToolbar\FieldTypeToolbarFactory; +use Ibexa\AdminUi\View\ContentTypeCreateView; +use Ibexa\AdminUi\View\ContentTypeEditView; use Pagerfanta\Adapter\ArrayAdapter; use Pagerfanta\Pagerfanta; use Symfony\Component\Form\FormInterface; @@ -170,13 +172,13 @@ public function listAction(ContentTypeGroup $group, string $routeName, int $page /** * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup $group * - * @return \Symfony\Component\HttpFoundation\Response + * @return \Symfony\Component\HttpFoundation\Response|\Ibexa\AdminUi\View\ContentTypeCreateView * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException * @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException */ - public function addAction(ContentTypeGroup $group): Response + public function addAction(ContentTypeGroup $group) { $this->denyAccessUnlessGranted(new Attribute('class', 'create')); $languages = $this->configResolver->getParameter('languages'); @@ -203,12 +205,15 @@ public function addAction(ContentTypeGroup $group): Response $language = $this->languageService->loadLanguage($mainLanguageCode); $form = $this->createUpdateForm($group, $contentTypeDraft, $language); - return $this->render('@ezdesign/content_type/create.html.twig', [ - 'content_type_group' => $group, - 'content_type' => $contentTypeDraft, - 'form' => $form->createView(), + $view = new ContentTypeCreateView('@ezdesign/content_type/create.html.twig'); + $view->setContentTypeGroup($group); + $view->setContentTypeDraft($contentTypeDraft); + $view->setForm($form); + $view->setParameters([ 'field_type_toolbar' => $this->fieldTypeToolbarFactory->create(), ]); + + return $view; } /** @@ -460,7 +465,7 @@ public function copyAction(Request $request, ContentTypeGroup $group, ContentTyp * @param \eZ\Publish\API\Repository\Values\Content\Language|null $language * @param \eZ\Publish\API\Repository\Values\Content\Language|null $baseLanguage * - * @return \Symfony\Component\HttpFoundation\Response + * @return \Symfony\Component\HttpFoundation\Response|\Ibexa\AdminUi\View\ContentTypeEditView * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException */ @@ -470,7 +475,7 @@ public function updateAction( ContentTypeDraft $contentTypeDraft, Language $language = null, Language $baseLanguage = null - ): Response { + ) { if (!$language) { $language = $this->getDefaultLanguage($contentTypeDraft); } @@ -525,13 +530,16 @@ public function updateAction( } } - return $this->render('@ezdesign/content_type/edit.html.twig', [ - 'content_type_group' => $group, - 'content_type' => $contentTypeDraft, - 'form' => $form->createView(), - 'language_code' => $baseLanguage ? $baseLanguage->languageCode : $language->languageCode, + $view = new ContentTypeEditView('@ezdesign/content_type/edit.html.twig'); + $view->setContentTypeGroup($group); + $view->setContentTypeDraft($contentTypeDraft); + $view->setForm($form); + $view->setLanguage($baseLanguage ?? $language); + $view->addParameters([ 'field_type_toolbar' => $this->fieldTypeToolbarFactory->create(), ]); + + return $view; } public function addFieldDefinitionFormAction( diff --git a/src/lib/View/ContentTypeCreateView.php b/src/lib/View/ContentTypeCreateView.php new file mode 100644 index 0000000000..5eae9272a8 --- /dev/null +++ b/src/lib/View/ContentTypeCreateView.php @@ -0,0 +1,68 @@ +contentTypeGroup; + } + + public function setContentTypeGroup(ContentTypeGroup $contentTypeGroup): void + { + $this->contentTypeGroup = $contentTypeGroup; + } + + public function getContentTypeDraft(): ContentTypeDraft + { + return $this->contentTypeDraft; + } + + public function setContentTypeDraft(ContentTypeDraft $contentTypeDraft): void + { + $this->contentTypeDraft = $contentTypeDraft; + } + + public function getForm(): FormInterface + { + return $this->form; + } + + public function setForm(FormInterface $form): void + { + $this->form = $form; + } + + /** + * @return array + */ + protected function getInternalParameters(): array + { + return [ + 'content_type_group' => $this->contentTypeGroup, + 'content_type' => $this->contentTypeDraft, + 'form' => $this->form ? $this->form->createView() : null, + ]; + } +} diff --git a/src/lib/View/ContentTypeEditView.php b/src/lib/View/ContentTypeEditView.php new file mode 100644 index 0000000000..47e210cd0d --- /dev/null +++ b/src/lib/View/ContentTypeEditView.php @@ -0,0 +1,83 @@ +contentTypeGroup; + } + + public function setContentTypeGroup(ContentTypeGroup $contentTypeGroup): void + { + $this->contentTypeGroup = $contentTypeGroup; + } + + public function getContentTypeDraft(): ContentTypeDraft + { + return $this->contentTypeDraft; + } + + public function setContentTypeDraft(ContentTypeDraft $contentTypeDraft): void + { + $this->contentTypeDraft = $contentTypeDraft; + } + + public function getLanguage(): ?Language + { + return $this->language; + } + + public function setLanguage(?Language $language): void + { + $this->language = $language; + } + + public function getForm(): FormInterface + { + return $this->form; + } + + public function setForm(FormInterface $form): void + { + $this->form = $form; + } + + /** + * @return array + */ + protected function getInternalParameters(): array + { + return [ + 'content_type_group' => $this->contentTypeGroup, + 'content_type' => $this->contentTypeDraft, + 'form' => $this->form ? $this->form->createView() : null, + 'language_code' => $this->language->languageCode, + ]; + } +}