From 5940f4a2a67ac1a39fdbee37513f3ab3c9ef0d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= <adam.wojs@ez.no> Date: Thu, 31 Jan 2019 14:05:22 +0100 Subject: [PATCH] EZP-30094: User is unable to change object state --- .../Controller/ObjectStateController.php | 34 +++++++++++++------ src/lib/Form/Factory/FormFactory.php | 10 ++++++ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/bundle/Controller/ObjectStateController.php b/src/bundle/Controller/ObjectStateController.php index 92c69f2ba7..2c8766a9c5 100644 --- a/src/bundle/Controller/ObjectStateController.php +++ b/src/bundle/Controller/ObjectStateController.php @@ -19,9 +19,14 @@ use EzSystems\EzPlatformAdminUi\Form\Data\ObjectState\ObjectStateDeleteData; use EzSystems\EzPlatformAdminUi\Form\Data\ObjectState\ObjectStatesDeleteData; use EzSystems\EzPlatformAdminUi\Form\Data\ObjectState\ObjectStateUpdateData; -use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory; use EzSystems\EzPlatformAdminUi\Form\SubmitHandler; +use EzSystems\EzPlatformAdminUi\Form\Type\ObjectState\ContentObjectStateUpdateType; +use EzSystems\EzPlatformAdminUi\Form\Type\ObjectState\ObjectStateCreateType; +use EzSystems\EzPlatformAdminUi\Form\Type\ObjectState\ObjectStateDeleteType; +use EzSystems\EzPlatformAdminUi\Form\Type\ObjectState\ObjectStatesDeleteType; +use EzSystems\EzPlatformAdminUi\Form\Type\ObjectState\ObjectStateUpdateType; use EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface; +use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Translation\TranslatorInterface; @@ -37,7 +42,7 @@ class ObjectStateController extends Controller /** @var \eZ\Publish\API\Repository\ObjectStateService */ private $objectStateService; - /** @var \EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory */ + /** @var \Symfony\Component\Form\FormFactoryInterface */ private $formFactory; /** @var \EzSystems\EzPlatformAdminUi\Form\SubmitHandler */ @@ -53,7 +58,7 @@ class ObjectStateController extends Controller * @param \EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface $notificationHandler * @param \Symfony\Component\Translation\TranslatorInterface $translator * @param \eZ\Publish\API\Repository\ObjectStateService $objectStateService - * @param \EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory $formFactory + * @param \Symfony\Component\Form\FormFactoryInterface $formFactory * @param \EzSystems\EzPlatformAdminUi\Form\SubmitHandler $submitHandler * @param \eZ\Publish\API\Repository\PermissionResolver $permissionResolver * @param array $languages @@ -62,7 +67,7 @@ public function __construct( NotificationHandlerInterface $notificationHandler, TranslatorInterface $translator, ObjectStateService $objectStateService, - FormFactory $formFactory, + FormFactoryInterface $formFactory, SubmitHandler $submitHandler, PermissionResolver $permissionResolver, array $languages @@ -86,7 +91,8 @@ public function listAction(ObjectStateGroup $objectStateGroup): Response /** @var ObjectState[] $objectStates */ $objectStates = $this->objectStateService->loadObjectStates($objectStateGroup); - $deleteObjectStatesForm = $this->formFactory->deleteObjectStates( + $deleteObjectStatesForm = $this->formFactory->create( + ObjectStatesDeleteType::class, new ObjectStatesDeleteData($this->getObjectStatesIds($objectStates)) ); @@ -112,7 +118,8 @@ public function listAction(ObjectStateGroup $objectStateGroup): Response */ public function viewAction(ObjectState $objectState): Response { - $deleteForm = $this->formFactory->deleteObjectState( + $deleteForm = $this->formFactory->create( + ObjectStateDeleteType::class, new ObjectStateDeleteData($objectState) )->createView(); @@ -135,7 +142,8 @@ public function addAction(Request $request, ObjectStateGroup $objectStateGroup): $this->denyAccessUnlessGranted(new Attribute('state', 'administrate')); $defaultLanguageCode = reset($this->languages); - $form = $this->formFactory->createObjectState( + $form = $this->formFactory->create( + ObjectStateCreateType::class, new ObjectStateCreateData() ); $form->handleRequest($request); @@ -183,7 +191,8 @@ function (ObjectStateCreateData $data) use ($defaultLanguageCode, $objectStateGr public function deleteAction(Request $request, ObjectState $objectState): Response { $this->denyAccessUnlessGranted(new Attribute('state', 'administrate')); - $form = $this->formFactory->deleteObjectState( + $form = $this->formFactory->create( + ObjectStateDeleteType::class, new ObjectStateDeleteData($objectState) ); $form->handleRequest($request); @@ -224,7 +233,8 @@ public function deleteAction(Request $request, ObjectState $objectState): Respon public function bulkDeleteAction(Request $request, int $objectStateGroupId): Response { $this->denyAccessUnlessGranted(new Attribute('state', 'administrate')); - $form = $this->formFactory->deleteObjectStates( + $form = $this->formFactory->create( + ObjectStatesDeleteType::class, new ObjectStatesDeleteData() ); $form->handleRequest($request); @@ -265,7 +275,8 @@ public function bulkDeleteAction(Request $request, int $objectStateGroupId): Res public function updateAction(Request $request, ObjectState $objectState): Response { $this->denyAccessUnlessGranted(new Attribute('state', 'administrate')); - $form = $this->formFactory->updateObjectState( + $form = $this->formFactory->create( + ObjectStateUpdateType::class, new ObjectStateUpdateData($objectState) ); $form->handleRequest($request); @@ -327,7 +338,8 @@ public function updateContentStateAction( throw $exception; } - $form = $this->formFactory->updateContentObjectState( + $form = $this->formFactory->create( + ContentObjectStateUpdateType::class, new ContentObjectStateUpdateData($contentInfo, $objectStateGroup) ); $form->handleRequest($request); diff --git a/src/lib/Form/Factory/FormFactory.php b/src/lib/Form/Factory/FormFactory.php index 3a555af2e4..5ce02e2d09 100644 --- a/src/lib/Form/Factory/FormFactory.php +++ b/src/lib/Form/Factory/FormFactory.php @@ -1136,6 +1136,8 @@ public function updateObjectStateGroup( * @param null|string $name * * @return FormInterface + * + * @deprecated since version 2.2, to be removed in 3.0. Use Use \Symfony\Component\Form\FormFactoryInterface::create directly instead. */ public function createObjectState( ?ObjectStateCreateData $data = null, @@ -1155,6 +1157,8 @@ public function createObjectState( * @param null|string $name * * @return FormInterface + * + * @deprecated since version 2.2, to be removed in 3.0. Use Use \Symfony\Component\Form\FormFactoryInterface::create directly instead. */ public function deleteObjectState( ObjectStateDeleteData $data = null, @@ -1172,6 +1176,8 @@ public function deleteObjectState( * @return FormInterface * * @throws InvalidOptionsException + * + * @deprecated since version 2.2, to be removed in 3.0. Use Use \Symfony\Component\Form\FormFactoryInterface::create directly instead. */ public function deleteObjectStates( ObjectStatesDeleteData $data = null, @@ -1187,6 +1193,8 @@ public function deleteObjectStates( * @param null|string $name * * @return FormInterface + * + * @deprecated since version 2.2, to be removed in 3.0. Use Use \Symfony\Component\Form\FormFactoryInterface::create directly instead. */ public function updateObjectState( ObjectStateUpdateData $data = null, @@ -1202,6 +1210,8 @@ public function updateObjectState( * @param null|string $name * * @return FormInterface + * + * @deprecated since version 2.2, to be removed in 3.0. Use Use \Symfony\Component\Form\FormFactoryInterface::create directly instead. */ public function updateContentObjectState( ContentObjectStateUpdateData $data,