]> Raphaƫl G. Git Repositories - packbundle/blobdiff - Form/CaptchaType.php
Remove path bundle parameter
[packbundle] / Form / CaptchaType.php
index a2ecb878d1da3bd5e1ff9b0535a6bf028142328b..015a91bac486f8a522540c2d2c0cc6b2e5040439 100644 (file)
@@ -11,6 +11,7 @@
 
 namespace Rapsys\PackBundle\Form;
 
+use Rapsys\PackBundle\RapsysPackBundle;
 use Rapsys\PackBundle\Util\ImageUtil;
 use Rapsys\PackBundle\Util\SluggerUtil;
 
@@ -21,6 +22,7 @@ use Symfony\Component\Form\FormBuilderInterface;
 use Symfony\Component\Form\FormError;
 use Symfony\Component\Form\FormEvent;
 use Symfony\Component\Form\FormEvents;
+use Symfony\Component\OptionsResolver\OptionsResolver;
 use Symfony\Contracts\Translation\TranslatorInterface;
 
 /**
@@ -46,9 +48,9 @@ class CaptchaType extends AbstractType {
         */
        public function buildForm(FormBuilderInterface $builder, array $options): void {
                //With image, slugger and translator
-               if ($this->image !== null && $this->slugger !== null && $this->translator !== null) {
+               if (!empty($options['captcha']) && $this->image !== null && $this->slugger !== null && $this->translator !== null) {
                        //Set captcha
-                       $captcha = $this->image->getCaptcha((new \DateTime('-1 year'))->getTimestamp());
+                       $captcha = $this->image->getCaptcha();
 
                        //Add captcha token
                        $builder->add('_captcha_token', HiddenType::class, ['data' => $captcha['token'], 'empty_data' => $captcha['token'], 'mapped' => false]);
@@ -61,6 +63,20 @@ class CaptchaType extends AbstractType {
                }
        }
 
+       /**
+        * {@inheritdoc}
+        */
+       public function configureOptions(OptionsResolver $resolver): void {
+               //Call parent configure options
+               parent::configureOptions($resolver);
+
+               //Set defaults
+               $resolver->setDefaults(['captcha' => false, 'translation_domain' => RapsysPackBundle::getAlias()]);
+
+               //Add extra captcha option
+               $resolver->setAllowedTypes('captcha', 'boolean');
+       }
+
        /**
         * Validate captcha
         *