title: Symfony - Edit User Entity without changing password
body: <p>I'm running Symfony 3.4.14 and I developed my own User Bundle, I have a very bad experience with FOS then I don't want to use anymore. My goal is to let the admin users  create/edit/remove users, I mean other users account.</p>
  
  <p>I made :</p>
  
  <ul>
  <li>the User entity</li>
  <li>the Login form</li>
  <li>the Registration form</li>
  </ul>
  
  <p>.. and I'm stuck with the Update form. I want to let the admins edit a user without editing the password, but to give them the opportunity to do it if needed. Below is my EditUserAction in controller :</p>
  
  <pre><code>&lt;?php
  
      /**
      * @Route("/admin/users/edit/{id}", requirements={"id" = "\d+"}, name="admin_users_edit")
      * @Template("@Core/admin/users_edit.html.twig")
      * @Security("has_role('ROLE_ADMIN')")
      */
      public function EditUserAction($id, Request $request, UserPasswordEncoderInterface $passwordEncoder)
      {
          $user = $this-&gt;getDoctrine()-&gt;getRepository('CoreBundle:User')-&gt;findOneBy([ 'id'=&gt;$id, 'deleted' =&gt; 0 ]);
          if ( $user )
          {
              $old_password = $user-&gt;getPassword();
              $form = $this-&gt;createForm(UserType::class, $user);
              $form-&gt;handleRequest($request);
              if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid())
              {
                  // If admin changed the user password
                  if ( $user-&gt;getPlainPassword() )
                  {
                      $password = $passwordEncoder-&gt;encodePassword($user, $user-&gt;getPlainPassword());
                      $user-&gt;setPassword($password);
                  }
                  // If admin didn't change the user password, we persist the old one
                  else
                  {
                      $user-&gt;setPassword($old_password);
                  }
                  $entityManager = $this-&gt;getDoctrine()-&gt;getManager();
                  $entityManager-&gt;persist($user);
                  $entityManager-&gt;flush();
              }
              return array('form' =&gt; $form-&gt;createView());
          }
          return $this-&gt;redirectToRoute('admin_users');
      }
  </code></pre>
  
  <p>Case 1 (when admin choose to change the user password) works well, but the other case (when admin don't want to change the password) fails. They are no way to let the 2 password inputs empty. I can't get rid of this validation error in the debug toolbar :</p>
  
  <pre><code>Path: data.plainPassword
  Message: This value should not be blank
  </code></pre>
  
  <p>In order to avoid this error, as you can see in my controller above, I try to keep the old one (may not be a best practice, I know).</p>