From 8b7a78168d0ba73a8ffb275042b53da508e2548e Mon Sep 17 00:00:00 2001 From: Mateusz Debinski Date: Tue, 18 Feb 2020 14:44:24 +0100 Subject: [PATCH 1/5] EZEE-2930: Added Language class to view --- bundle/Controller/UserController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bundle/Controller/UserController.php b/bundle/Controller/UserController.php index 89818ed45..8279cbf08 100644 --- a/bundle/Controller/UserController.php +++ b/bundle/Controller/UserController.php @@ -160,7 +160,7 @@ public function editAction( throw new CoreUnauthorizedException('content', 'edit', ['userId' => $contentId]); } $contentType = $this->contentTypeService->loadContentType($user->contentInfo->contentTypeId); - + $language = $this->languageService->loadLanguage($language); $userUpdate = (new UserUpdateMapper())->mapToFormData($user, $contentType, [ 'languageCode' => $language, ]); @@ -168,7 +168,7 @@ public function editAction( UserUpdateType::class, $userUpdate, [ - 'languageCode' => $language, + 'languageCode' => $language->languageCode, 'mainLanguageCode' => $user->contentInfo->mainLanguageCode, ] ); @@ -183,7 +183,8 @@ public function editAction( return new UserUpdateView(null, [ 'form' => $form->createView(), - 'languageCode' => $language, + 'languageCode' => $language->languageCode, + 'language' => $language, 'contentType' => $contentType, 'user' => $user, ]); From e8e26ed3df784b0c1699d276a09ba493e17bf5b8 Mon Sep 17 00:00:00 2001 From: Mateusz Debinski Date: Tue, 18 Feb 2020 15:25:55 +0100 Subject: [PATCH 2/5] Corrected if $language is empty get default language --- bundle/Controller/UserController.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bundle/Controller/UserController.php b/bundle/Controller/UserController.php index 8279cbf08..06e729934 100644 --- a/bundle/Controller/UserController.php +++ b/bundle/Controller/UserController.php @@ -155,20 +155,21 @@ public function editAction( ?string $language = null, Request $request ) { + $languageCode = $language; $user = $this->userService->loadUser($contentId); if (!$this->permissionResolver->canUser('content', 'edit', $user)) { throw new CoreUnauthorizedException('content', 'edit', ['userId' => $contentId]); } $contentType = $this->contentTypeService->loadContentType($user->contentInfo->contentTypeId); - $language = $this->languageService->loadLanguage($language); + $language = $this->languageService->loadLanguage($languageCode ?:$this->languageService->getDefaultLanguageCode()); $userUpdate = (new UserUpdateMapper())->mapToFormData($user, $contentType, [ - 'languageCode' => $language, + 'languageCode' => $languageCode, ]); $form = $this->createForm( UserUpdateType::class, $userUpdate, [ - 'languageCode' => $language->languageCode, + 'languageCode' => $languageCode, 'mainLanguageCode' => $user->contentInfo->mainLanguageCode, ] ); @@ -183,7 +184,7 @@ public function editAction( return new UserUpdateView(null, [ 'form' => $form->createView(), - 'languageCode' => $language->languageCode, + 'languageCode' => $languageCode, 'language' => $language, 'contentType' => $contentType, 'user' => $user, From b984bc6772523f4bf1739210061f67e6fd3ccd3b Mon Sep 17 00:00:00 2001 From: Mateusz Debinski Date: Tue, 18 Feb 2020 15:35:23 +0100 Subject: [PATCH 3/5] Added missing location to view --- bundle/Controller/UserController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bundle/Controller/UserController.php b/bundle/Controller/UserController.php index 06e729934..fbaaf0899 100644 --- a/bundle/Controller/UserController.php +++ b/bundle/Controller/UserController.php @@ -182,12 +182,15 @@ public function editAction( } } + $location = $this->locationService->loadLocation($user->versionInfo->contentInfo->mainLocationId); + return new UserUpdateView(null, [ 'form' => $form->createView(), 'languageCode' => $languageCode, 'language' => $language, 'contentType' => $contentType, 'user' => $user, + 'location' => $location ]); } } From 984441e1d58d1883ce1152b037b9a5cbb0564834 Mon Sep 17 00:00:00 2001 From: Mateusz Debinski Date: Fri, 21 Feb 2020 15:18:36 +0100 Subject: [PATCH 4/5] Added missing parameter parentLocation in createAction, changed from optional to mandatory parameters $versionNo and $language in editAction, corrected problem with permissions with multi locations --- bundle/Controller/UserController.php | 36 ++++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/bundle/Controller/UserController.php b/bundle/Controller/UserController.php index fbaaf0899..afb700a98 100644 --- a/bundle/Controller/UserController.php +++ b/bundle/Controller/UserController.php @@ -123,6 +123,7 @@ public function createAction( return new UserCreateView(null, [ 'form' => $form->createView(), 'language' => $language, + 'parentLocation' => $location, 'contentType' => $contentType, 'parentGroup' => $parentGroup, ]); @@ -131,9 +132,9 @@ public function createAction( /** * Displays a user update form that updates user data and related content item. * - * @param int|null $contentId ContentType id to create - * @param int|null $versionNo Version number the version should be created from. Defaults to the currently published one. - * @param string|null $language Language code to create the version in (eng-GB, ger-DE, ...)) + * @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 string $language Language code to create the version in (eng-GB, ger-DE, ...)) * @param Request $request * * @return UserUpdateView|Response @@ -151,25 +152,24 @@ public function createAction( */ public function editAction( int $contentId, - ?int $versionNo = null, - ?string $language = null, + int $versionNo, + string $language, Request $request ) { - $languageCode = $language; $user = $this->userService->loadUser($contentId); if (!$this->permissionResolver->canUser('content', 'edit', $user)) { throw new CoreUnauthorizedException('content', 'edit', ['userId' => $contentId]); } $contentType = $this->contentTypeService->loadContentType($user->contentInfo->contentTypeId); - $language = $this->languageService->loadLanguage($languageCode ?:$this->languageService->getDefaultLanguageCode()); + $userUpdate = (new UserUpdateMapper())->mapToFormData($user, $contentType, [ - 'languageCode' => $languageCode, + 'languageCode' => $language, ]); $form = $this->createForm( UserUpdateType::class, $userUpdate, [ - 'languageCode' => $languageCode, + 'languageCode' => $language, 'mainLanguageCode' => $user->contentInfo->mainLanguageCode, ] ); @@ -182,15 +182,25 @@ public function editAction( } } - $location = $this->locationService->loadLocation($user->versionInfo->contentInfo->mainLocationId); + try { + // assume main location if no location was provided + $location = $this->locationService->loadLocation((int) + $user->versionInfo->contentInfo->mainLocationId); + } catch (UnauthorizedException $e) { + // if no access to the main location assume content has multiple locations and first of them can be used + $availableLocations = $this->locationService->loadLocations($user->versionInfo->contentInfo); + $location = array_shift($availableLocations); + } + return new UserUpdateView(null, [ 'form' => $form->createView(), - 'languageCode' => $languageCode, - 'language' => $language, + 'languageCode' => $language, + 'language' => $this->languageService->loadLanguage($language), 'contentType' => $contentType, 'user' => $user, - 'location' => $location + 'location' => $location, + 'parentLocation' => $location ]); } } From c78ce7bfd205188218bcbca9ac5878b183f55458 Mon Sep 17 00:00:00 2001 From: Mateusz Debinski Date: Fri, 28 Feb 2020 15:33:55 +0100 Subject: [PATCH 5/5] EZEE-2930: Set correct parentLocation --- bundle/Controller/UserController.php | 67 +++++++++++++++------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/bundle/Controller/UserController.php b/bundle/Controller/UserController.php index afb700a98..451f0cbf8 100644 --- a/bundle/Controller/UserController.php +++ b/bundle/Controller/UserController.php @@ -6,6 +6,7 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ + namespace EzSystems\RepositoryFormsBundle\Controller; use eZ\Bundle\EzPublishCoreBundle\Controller; @@ -16,7 +17,6 @@ use eZ\Publish\API\Repository\LocationService; use eZ\Publish\API\Repository\PermissionResolver; use eZ\Publish\API\Repository\UserService; -use eZ\Publish\Core\Base\Exceptions\BadStateException; use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException; use eZ\Publish\Core\Base\Exceptions\InvalidArgumentType; use EzSystems\RepositoryForms\Data\Mapper\UserCreateMapper; @@ -120,13 +120,15 @@ public function createAction( } } - return new UserCreateView(null, [ - 'form' => $form->createView(), - 'language' => $language, - 'parentLocation' => $location, - 'contentType' => $contentType, - 'parentGroup' => $parentGroup, - ]); + return new UserCreateView( + null, [ + 'form' => $form->createView(), + 'language' => $language, + 'parentLocation' => $location, + 'contentType' => $contentType, + 'parentGroup' => $parentGroup, + ] + ); } /** @@ -139,16 +141,11 @@ public function createAction( * * @return UserUpdateView|Response * - * @throws \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException - * @throws \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException - * @throws \Symfony\Component\OptionsResolver\Exception\NoSuchOptionException - * @throws \Symfony\Component\OptionsResolver\Exception\MissingOptionsException - * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - * @throws \Symfony\Component\OptionsResolver\Exception\AccessException - * @throws InvalidArgumentType - * @throws UnauthorizedException - * @throws NotFoundException - * @throws BadStateException If the version isn't editable, or if there is no editable version. + * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException + * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType + * @throws \eZ\Publish\Core\Base\Exceptions\UnauthorizedException */ public function editAction( int $contentId, @@ -184,23 +181,33 @@ public function editAction( try { // assume main location if no location was provided - $location = $this->locationService->loadLocation((int) - $user->versionInfo->contentInfo->mainLocationId); + $location = $this->locationService->loadLocation( + (int)$user->versionInfo->contentInfo->mainLocationId + ); } catch (UnauthorizedException $e) { // if no access to the main location assume content has multiple locations and first of them can be used - $availableLocations = $this->locationService->loadLocations($user->versionInfo->contentInfo); + $availableLocations = $this->locationService->loadLocations( + $user->versionInfo->contentInfo + ); $location = array_shift($availableLocations); } + $parentLocation = null; + try { + $parentLocation = $this->locationService->loadLocation($location->parentLocationId); + } catch (UnauthorizedException $e) { + } - return new UserUpdateView(null, [ - 'form' => $form->createView(), - 'languageCode' => $language, - 'language' => $this->languageService->loadLanguage($language), - 'contentType' => $contentType, - 'user' => $user, - 'location' => $location, - 'parentLocation' => $location - ]); + return new UserUpdateView( + null, [ + 'form' => $form->createView(), + 'languageCode' => $language, + 'language' => $this->languageService->loadLanguage($language), + 'contentType' => $contentType, + 'user' => $user, + 'location' => $location, + 'parentLocation' => $parentLocation, + ] + ); } }