From a9b2711b7db4e83934bb4a8ba6ab3f4376ec344b Mon Sep 17 00:00:00 2001 From: werrolf Date: Tue, 4 Feb 2020 14:27:27 +0100 Subject: [PATCH] Fix invalid disabling strategy for username form field --- src/FOM/UserBundle/Controller/UserController.php | 3 --- src/FOM/UserBundle/Form/Type/UserType.php | 9 +++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/FOM/UserBundle/Controller/UserController.php b/src/FOM/UserBundle/Controller/UserController.php index 4a4ecf9..6cf6378 100644 --- a/src/FOM/UserBundle/Controller/UserController.php +++ b/src/FOM/UserBundle/Controller/UserController.php @@ -122,9 +122,6 @@ protected function userActionCommon(Request $request, User $user) 'acl_permission' => $this->isGranted('OWNER', $user), 'currentUser' => $this->getUser(), )); - if (!$isNew && !$groupPermission) { - $form->get('username')->setDisabled(true); - } $form->handleRequest($request); diff --git a/src/FOM/UserBundle/Form/Type/UserType.php b/src/FOM/UserBundle/Form/Type/UserType.php index 53226ad..3120cbc 100644 --- a/src/FOM/UserBundle/Form/Type/UserType.php +++ b/src/FOM/UserBundle/Form/Type/UserType.php @@ -6,6 +6,8 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Doctrine\ORM\EntityRepository; +use Symfony\Component\Form\FormInterface; +use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; class UserType extends AbstractType @@ -69,6 +71,13 @@ public function buildForm(FormBuilderInterface $builder, array $options) } } + public function finishView(FormView $view, FormInterface $form, array $options) + { + $user = $form->getData(); + $usernameEnabled = $options['group_permission'] || !$user->getId(); + $view['username']->vars['disabled'] = !$usernameEnabled; + } + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array(