public function edit(Request $request, $id)
{
if (!($userEntity = $this->getEditableUser($id))) {
return $this->redirectToRoute('users');
}
// Get the base form
$form = $this->getUserForm($userEntity, true);
// Get the extra editable fields
$form = $this->getUserEditFields($form, $id);
// Set the validation
$form = $this->setUserFormValidation($form, true);
// Generate the form
$form = $form->getForm();
$currentUser = $this->getUser();
// Check if the form was POST-ed, and valid. If so, store the user.
if ($request->isMethod('POST')) {
$userEntity = $this->validateUserForm($request, $form, false);
if ($userEntity !== false && $userEntity->getId() == $currentUser->getId() && $userEntity->getUsername() !== $currentUser->getUsername()) {
// If the current user changed their own login name, the session
// is effectively invalidated. If so, we must redirect to the
// login page with a flash message.
$this->flashes()->error(Trans::__('page.edit-users.message.change-self'));
return $this->redirectToRoute('login');
} elseif ($userEntity !== false) {
// Return to the 'Edit users' screen.
return $this->redirectToRoute('users');
}
}
/** @var \Symfony\Component\Form\FormView|\Symfony\Component\Form\FormView[] $formView */
$formView = $form->createView();
$manipulatableRoles = $this->app['permissions']->getManipulatableRoles($currentUser->toArray());
foreach ($formView['roles'] as $role) {
if (!in_array($role->vars['value'], $manipulatableRoles)) {
$role->vars['attr']['disabled'] = 'disabled';
}
}
$context = ['kind' => empty($id) ? 'create' : 'edit', 'form' => $formView, 'note' => '', 'displayname' => $userEntity['displayname']];
return $this->render('@bolt/edituser/edituser.twig', $context);
}