/** * Creates a new RoleDraft for an existing Role. * * @since 6.0 * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a RoleDraft * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the Role already has a RoleDraft that will need to be removed first * * @param \eZ\Publish\API\Repository\Values\User\Role $role * * @return \eZ\Publish\API\Repository\Values\User\RoleDraft */ public function createRoleDraft(APIRole $role) { if ($this->repository->hasAccess('role', 'create') !== true) { throw new UnauthorizedException('role', 'create'); } try { $this->userHandler->loadRole($role->id, Role::STATUS_DRAFT); // Throw exception, so platformui et al can do conflict management. Follow-up: EZP-24719 throw new InvalidArgumentException('$role', "Cannot create a draft for role '{$role->identifier}' because another draft exists"); } catch (APINotFoundException $e) { $this->repository->beginTransaction(); try { $spiRole = $this->userHandler->createRoleDraft($role->id); $this->repository->commit(); } catch (Exception $e) { $this->repository->rollback(); throw $e; } } return $this->roleDomainMapper->buildDomainRoleDraftObject($spiRole); }