protected function updateUser(Request $request, User $user) { list($data, $response) = $this->decodeDataAndVerifyCsrf($request); if (!$response) { $oldRole = $user->getRole(); $this->mapUser($user, $data); $validator = $this->get('validator'); $errors = $validator->validate($user); if ($oldRole != $user->getRole() && !$this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) { $errors->add(new ConstraintViolation('users.changeRoleDenied', 'users.changeRoleDenied', [], $user, 'role', $user->getRole())); } if (count($errors) > 0) { $response = $this->getTranslatedValidationResponse($errors); } else { $em = $this->getDoctrine()->getManager(); $em->merge($user); $em->flush(); $response = new Response('', Response::HTTP_NO_CONTENT); } } return $response; }