diff --git a/src/Controller/ProfileController.php b/src/Controller/ProfileController.php index 42d86dfc..49b4cd30 100644 --- a/src/Controller/ProfileController.php +++ b/src/Controller/ProfileController.php @@ -309,15 +309,18 @@ final class ProfileController extends AbstractController private function createEditForm(User $user): FormInterface { + $currentUser = $this->getUser(); + return $this->createForm( UserEditType::class, $user, [ 'action' => $this->generateUrl('user_profile_edit', ['username' => $user->getUserIdentifier()]), 'method' => 'POST', - 'include_active_flag' => ($user->getId() !== $this->getUser()->getId()), + 'include_active_flag' => $user !== $currentUser, 'include_preferences' => true, 'include_supervisor' => $this->isGranted('supervisor', $user), + 'include_username' => $currentUser->isSuperAdmin() && $currentUser !== $user, 'include_password_reset' => $this->isGranted('password', $user), ] ); diff --git a/src/Form/UserEditType.php b/src/Form/UserEditType.php index c73fe932..81771492 100644 --- a/src/Form/UserEditType.php +++ b/src/Form/UserEditType.php @@ -42,6 +42,14 @@ class UserEditType extends AbstractType $user = $options['data']; } + if ($options['include_username']) { + $builder->add('username', TextType::class, [ + 'label' => 'user_identifier', + 'help' => 'user_identifier.help', + 'required' => true, + ]); + } + $builder->add('alias', TextType::class, [ 'label' => 'alias', 'required' => false, @@ -117,6 +125,7 @@ class UserEditType extends AbstractType 'include_active_flag' => true, 'include_preferences' => true, 'include_supervisor' => true, + 'include_username' => false, 'include_password_reset' => true, ]); } diff --git a/templates/user/layout.html.twig b/templates/user/layout.html.twig index 8cde0640..b76e0244 100644 --- a/templates/user/layout.html.twig +++ b/templates/user/layout.html.twig @@ -15,7 +15,7 @@