public function setUser(ResourceEvent $event)
    {
        /** @var UserSessionInterface|null $resource */
        $resource = $event->getSubject();

        if (is_null($resource)) {
            return;
        }

        /** @var UserInterface $user */
        if (!$user = $this->repository->find($this->request->get('user'))) {
            throw new NotFoundHttpException('User not found.');
        }

        if ($user->hasRole(UserInterface::ROLE_ADMIN)) {
            throw new NotFoundHttpException("Can't create a questionnaire for administrator.");
        }

        $resource->setUser($user);
    }
public function setUser(ResourceEvent $event)
    {
        /** @var UserSessionInterface|null $resource */
        $resource = $event->getSubject();

        if (is_null($resource)) {
            return;
        }

        /** @var UserInterface $user */
        if (!$user = $this->repository->find($this->request->get('user'))) {
            throw new NotFoundHttpException('User not found.');
        }

        if ($user->hasRole(UserInterface::ROLE_ADMIN)) {
            throw new NotFoundHttpException("Can't create a questionnaire for administrator.");
        }

        $resource->setUser($user);
    }
public function setUser ( ResourceEvent $ event ) { /** @var UserSessionInterface|null $resource */ $ resource = $ event -> getSubject ( ) ; if ( is_null ( $ resource ) ) { return ; } /** @var UserInterface $user */ if ( ! $ user = $ this -> repository -> find ( $ this -> request -> get ( 'user' ) ) ) { throw new NotFoundHttpException ( 'User not found.' ) ; } if ( $ user -> hasRole ( UserInterface :: ROLE_ADMIN ) ) { throw new NotFoundHttpException ( "Can't create a questionnaire for administrator." ) ; } $ resource -> setUser ( $ user ) ; }
Find and Set user

@param ResourceEvent $event
Find and Set user