From 23bb2ffdb2eeba86ad000d7a0211498ee3ee1bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Fri, 21 Sep 2018 14:24:02 +0200 Subject: [PATCH] EZP-29269: User draft is not discarded on edition cancel (#240) * EZP-29269: User draft is not discarded on edition cancel * EZP-29269: User draft is not discarded on edition cancel - remove repository dependency * EZP-29269: Introducing new route for user handling * EZP-29269: Fixing behat tests * EZP-29269: fixed change list * EZP-29269: exposed ez_user_update route --- bundle/Resources/config/routing.yml | 9 +- bundle/Resources/config/services.yml | 10 -- doc/bc/changes-2.3.md | 11 ++ .../user_fieldtype_edit_form.feature | 4 +- lib/Behat/Context/FieldTypeFormContext.php | 15 ++- lib/EventListener/UserEditListener.php | 126 ------------------ 6 files changed, 33 insertions(+), 142 deletions(-) create mode 100644 doc/bc/changes-2.3.md delete mode 100644 lib/EventListener/UserEditListener.php diff --git a/bundle/Resources/config/routing.yml b/bundle/Resources/config/routing.yml index b4b519b51..7b12127dc 100644 --- a/bundle/Resources/config/routing.yml +++ b/bundle/Resources/config/routing.yml @@ -37,11 +37,14 @@ ez_user_register_confirmation: _controller: "ezrepoforms.controller.user_register:registerConfirmAction" ez_user_create: - path: /user/create + path: /user/create/{contentTypeIdentifier}/{language}/{parentLocationId} defaults: _controller: "ezrepoforms.controller.user:createAction" ez_user_update: - path: /user/update + path: /user/update/{contentId}/{versionNo}/{language} defaults: - _controller: "ezrepoforms.controller.user:updateAction" + _controller: "ezrepoforms.controller.user:editAction" + options: + expose: true + diff --git a/bundle/Resources/config/services.yml b/bundle/Resources/config/services.yml index 33a22e137..c6ecb8ba8 100644 --- a/bundle/Resources/config/services.yml +++ b/bundle/Resources/config/services.yml @@ -50,7 +50,6 @@ parameters: ezrepoforms.user_register.registration_group_loader.configurable.class: EzSystems\RepositoryForms\User\ConfigurableRegistrationGroupLoader ezrepoforms.user_register.registration_content_type_loader.configurable.class: EzSystems\RepositoryForms\User\ConfigurableRegistrationContentTypeLoader ezrepoforms.view_templates_listener.class: EzSystems\RepositoryForms\EventListener\ViewTemplatesListener - ezrepoforms.user_edit_listener.class: EzSystems\RepositoryForms\EventListener\UserEditListener ezrepoforms.form_data_mapper.user_register.class: EzSystems\RepositoryForms\Data\Mapper\UserRegisterMapper @@ -314,15 +313,6 @@ services: - [setViewTemplate, ['EzSystems\RepositoryForms\Content\View\ContentCreateDraftView', "$content_edit.templates.create_draft$"]] - [setPagelayout, ["$pagelayout$"]] - ezrepoforms.user_edit_listener: - class: "%ezrepoforms.user_edit_listener.class%" - arguments: - - "@ezpublish.api.service.content_type" - - "@ezpublish.api.service.content" - - "@ezrepoforms.controller.user" - tags: - - { name: kernel.event_subscriber } - ezrepoforms.translation.extractor.sorting: class: EzSystems\RepositoryForms\Translation\SortingTranslationExtractor tags: diff --git a/doc/bc/changes-2.3.md b/doc/bc/changes-2.3.md new file mode 100644 index 000000000..6851db543 --- /dev/null +++ b/doc/bc/changes-2.3.md @@ -0,0 +1,11 @@ +# Backwards compatibility changes + +Changes affecting version compatibility with former or future versions. + +## Removed features + +- EZP-29269: Editing content with user content field no longer results with draft creation. + + As part of it : + - `\EzSystems\RepositoryForms\EventListener\UserEditListener` was removed + - Existing routes `ez_user_create` and `ez_user_update` were changed in order to comply with new flow diff --git a/features/FieldTypeForm/user_fieldtype_edit_form.feature b/features/FieldTypeForm/user_fieldtype_edit_form.feature index 28c1e1557..c60d658e2 100644 --- a/features/FieldTypeForm/user_fieldtype_edit_form.feature +++ b/features/FieldTypeForm/user_fieldtype_edit_form.feature @@ -7,7 +7,7 @@ Background: Given a Content Type with a user field definition Scenario: The attributes of a user field have a form representation - When I view the edit form for this field + When I view the edit user form for this field Then the edit form should contain an identifiable widget for user field definition And it should contain the following set of labels, and input fields of the following types: | label | type | @@ -18,5 +18,5 @@ Scenario: The attributes of a user field have a form representation Scenario: The input fields are flagged as required when the field definition is required Given the field definition is marked as required - When I view the edit form for this field + When I view the edit user form for this field Then the value input fields for user field should be flagged as required diff --git a/lib/Behat/Context/FieldTypeFormContext.php b/lib/Behat/Context/FieldTypeFormContext.php index abb1c31bd..51a7ee7cb 100644 --- a/lib/Behat/Context/FieldTypeFormContext.php +++ b/lib/Behat/Context/FieldTypeFormContext.php @@ -86,6 +86,19 @@ public function iEditOrCreateContentOfThisType() ); } + /** + * @When /^I view the edit user form for this field$/ + */ + public function iEditOrCreateContentOfUserType() + { + $this->visitPath( + sprintf( + '/user/create/%s/eng-GB/2', + $this->contentTypeContext->getCurrentContentType()->identifier + ) + ); + } + /** * @Then the edit form should contain an identifiable widget for :fieldTypeIdentifier field definition */ @@ -156,7 +169,7 @@ public function theFieldDefinitionIsMarkedAsRequired() /** * @Then the value input fields for :fieldIdentifier field should be flagged as required */ - public function theInputFieldsShouldBeFlaggedAsRequired($fieldTypeIdentifier) + public function theInputFieldsShouldBeFlaggedAsRequired(string $fieldTypeIdentifier) { $inputNodeElements = $this->getSession()->getPage()->findAll( 'css', diff --git a/lib/EventListener/UserEditListener.php b/lib/EventListener/UserEditListener.php deleted file mode 100644 index be7ea6011..000000000 --- a/lib/EventListener/UserEditListener.php +++ /dev/null @@ -1,126 +0,0 @@ -contentTypeService = $contentTypeService; - $this->contentService = $contentService; - $this->userController = $userController; - } - - public static function getSubscribedEvents() - { - return [ - KernelEvents::CONTROLLER => [ - ['onControllerUserCreate', 20], - ['onControllerUserEdit', 30], - ], - ]; - } - - public function onControllerUserCreate(FilterControllerEvent $event) - { - $request = $event->getRequest(); - - if (self::CONTENT_CREATE_ROUTE === $request->attributes->get('_route')) { - $routeParams = $request->attributes->get('_route_params', ['contentTypeIdentifier' => null]); - $contentTypeIdentifier = $routeParams['contentTypeIdentifier']; - if (null !== $contentTypeIdentifier) { - try { - $contentType = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); - $isUserBasedContentType = $this->hasUserField($contentType); - } catch (NotFoundException $e) { - return; - } - - if (!$isUserBasedContentType) { - return; - } - - $event->getRequest()->attributes->set('_controller', [$this->userController, 'createAction']); - $event->setController([$this->userController, 'createAction']); - } - } - } - - public function onControllerUserEdit(FilterControllerEvent $event) - { - $request = $event->getRequest(); - - if (self::CONTENT_EDIT_ROUTE === $request->attributes->get('_route')) { - $routeParams = $request->attributes->get('_route_params', ['contentId' => null]); - $contentId = $routeParams['contentId']; - if (null !== $contentId) { - try { - $content = $this->contentService->loadContent($contentId); - $contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId); - $isUserBasedContentType = $this->hasUserField($contentType); - } catch (NotFoundException $e) { - return; - } - - if (!$isUserBasedContentType) { - return; - } - - $event->getRequest()->attributes->set('_controller', [$this->userController, 'editAction']); - $event->setController([$this->userController, 'editAction']); - } - } - } - - /** - * @param ContentType $contentType - * - * @return bool - */ - private function hasUserField(ContentType $contentType): bool - { - foreach ($contentType->getFieldDefinitions() as $fieldDefinition) { - if (self::USER_FIELD_TYPE === $fieldDefinition->fieldTypeIdentifier) { - return true; - } - } - - return false; - } -}