public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('email', 'email', ['label' => 'E-mail', 'required' => true, 'constraints' => [new Assert\NotBlank(), new Assert\Email(), NewEmail::create($this->app)]]);
     $builder->add('password', 'repeated', ['type' => 'password', 'required' => true, 'invalid_message' => 'Please provide the same passwords.', 'first_name' => 'password', 'second_name' => 'confirm', 'first_options' => ['label' => 'Password'], 'second_options' => ['label' => 'Password (confirmation)'], 'constraints' => [new Assert\NotBlank(), new Assert\Length(['min' => 5])]]);
     if ($this->app->hasTermsOfUse()) {
         $builder->add('accept-tou', 'checkbox', ['label' => 'Terms of Use', 'mapped' => false, "constraints" => [new Assert\True(["message" => "Please accept the Terms and conditions in order to register."])]]);
     }
     $builder->add('provider-id', 'hidden');
     $choices = $baseIds = [];
     foreach ($this->app['registration.manager']->getRegistrationSummary() as $baseInfo) {
         $dbName = $baseInfo['config']['db-name'];
         foreach ($baseInfo['config']['collections'] as $baseId => $collInfo) {
             if (false === $collInfo['can-register']) {
                 continue;
             }
             $choices[$dbName][$baseId] = $collInfo['coll-name'];
             $baseIds[] = $baseId;
         }
     }
     if (!$this->app['conf']->get(['registry', 'registration', 'auto-select-collections'])) {
         $builder->add('collections', 'choice', ['choices' => $choices, 'multiple' => true, 'expanded' => false, 'constraints' => [new Assert\Choice(['choices' => $baseIds, 'minMessage' => 'You must select at least %s collection.', 'multiple' => true, 'min' => 1])]]);
     }
     foreach ($this->params as $param) {
         $name = $param['name'];
         if (!preg_match('/[a-zA-Z]+/', $name)) {
             throw new InvalidArgumentException(sprintf('%s is not a valid fieldname'));
         }
         if (isset($this->available[$name])) {
             $options = array_merge($this->available[$name], ['required' => $param['required']]);
             if (!$param['required']) {
                 unset($options['constraints']);
             }
             unset($options['type']);
             $builder->add(StringHelper::camelize($name, '-'), $this->getType($name), $options);
         }
     }
 }
Esempio n. 2
0
 public function testBlankIsNotAlreadyRegistered()
 {
     $constraint = NewEmail::create(self::$DI['app']);
     $this->assertFalse($constraint->isAlreadyRegistered(''));
 }