Skip to content

Commit

Permalink
EZEE-2930: Added Language obj. instance to User create/edit views (#334)
Browse files Browse the repository at this point in the history
* EZEE-2930: Added Language class to view

* Corrected if $language is empty get default language

* Added missing location to view

* Added missing parameter parentLocation in createAction, changed from optional to mandatory parameters $versionNo and $language in editAction, corrected problem with permissions with multi locations

* EZEE-2930: Set correct parentLocation
  • Loading branch information
mateuszdebinski authored Mar 16, 2020
1 parent 36a6e44 commit 68cf3c3
Showing 1 changed file with 50 additions and 28 deletions.
78 changes: 50 additions & 28 deletions bundle/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -120,39 +120,37 @@ public function createAction(
}
}

return new UserCreateView(null, [
'form' => $form->createView(),
'language' => $language,
'contentType' => $contentType,
'parentGroup' => $parentGroup,
]);
return new UserCreateView(
null, [
'form' => $form->createView(),
'language' => $language,
'parentLocation' => $location,
'contentType' => $contentType,
'parentGroup' => $parentGroup,
]
);
}

/**
* 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
*
* @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,
?int $versionNo = null,
?string $language = null,
int $versionNo,
string $language,
Request $request
) {
$user = $this->userService->loadUser($contentId);
Expand Down Expand Up @@ -181,11 +179,35 @@ public function editAction(
}
}

return new UserUpdateView(null, [
'form' => $form->createView(),
'languageCode' => $language,
'contentType' => $contentType,
'user' => $user,
]);
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);
}

$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' => $parentLocation,
]
);
}
}

0 comments on commit 68cf3c3

Please sign in to comment.