浏览代码

Move password field into main buildForm method

Not quite as concise as it could've been, but at this point we just
need to support PHP 5.3 with minimum fuss. Slapping everything in one
block is the easiest way to avoid any other issues.
Dave Shoreman 11 年之前
父节点
当前提交
ac649679dd
共有 1 个文件被更改,包括 8 次插入17 次删除
  1. 8 17
      src/Packagist/WebBundle/Form/Type/ProfileFormType.php

+ 8 - 17
src/Packagist/WebBundle/Form/Type/ProfileFormType.php

@@ -28,30 +28,21 @@ class ProfileFormType extends BaseType
         $builder->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
                 ->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'));
 
-        // Horrible hack for people stuck in the past on PHP5.3
-        $self = $this;
-        $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) use ($self)
+        $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event)
         {
             if ( ! ($user = $event->getData())) return;
 
             if ( ! $user->getGithubId()) {
-                $self->addPasswordField($event);
+                $event->getForm()->add('current_password', 'password', array(
+                    'label' => 'form.current_password',
+                    'translation_domain' => 'FOSUserBundle',
+                    'mapped' => false,
+                    'constraints' => new UserPassword(),
+                ));
             }
         });
 
-        $builder->add('failureNotifications', null, array(
-            'required' => false,
-        ));
-    }
-
-    private function addPasswordField($event)
-    {
-        $event->getForm()->add('current_password', 'password', array(
-            'label' => 'form.current_password',
-            'translation_domain' => 'FOSUserBundle',
-            'mapped' => false,
-            'constraints' => new UserPassword(),
-        ));
+        $builder->add('failureNotifications', null, array('required' => false, 'label' => 'Notify me of package update failures'));
     }
 
     /**