]> Raphaƫl G. Git Repositories - packbundle/blobdiff - Form/CaptchaType.php
Add header and trailer to range command output
[packbundle] / Form / CaptchaType.php
index 83f3b1be998bf14b404e1b0cc2cbc9a7df193f27..c3a5f69c4559e8d588ad40d62f5453dcc8f8c0a2 100644 (file)
@@ -21,6 +21,7 @@ use Symfony\Component\Form\FormBuilderInterface;
 use Symfony\Component\Form\FormError;
 use Symfony\Component\Form\FormEvent;
 use Symfony\Component\Form\FormEvents;
 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;
 
 /**
 use Symfony\Contracts\Translation\TranslatorInterface;
 
 /**
@@ -32,8 +33,8 @@ class CaptchaType extends AbstractType {
        /**
         * Constructor
         *
        /**
         * Constructor
         *
-        * @param ?ImageUtil $image
-        * @param ?SluggerUtil $slugger
+        * @param ?ImageUtil $image The image instance
+        * @param ?SluggerUtil $slugger The slugger instance
         * @param ?TranslatorInterface $translator The translator instance
         */
        public function __construct(protected ?ImageUtil $image = null, protected ?SluggerUtil $slugger = null, protected ?TranslatorInterface $translator = null) {
         * @param ?TranslatorInterface $translator The translator instance
         */
        public function __construct(protected ?ImageUtil $image = null, protected ?SluggerUtil $slugger = null, protected ?TranslatorInterface $translator = null) {
@@ -46,7 +47,7 @@ class CaptchaType extends AbstractType {
         */
        public function buildForm(FormBuilderInterface $builder, array $options): void {
                //With image, slugger and translator
         */
        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());
 
                        //Set captcha
                        $captcha = $this->image->getCaptcha((new \DateTime('-1 year'))->getTimestamp());
 
@@ -61,6 +62,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]);
+
+               //Add extra captcha option
+               $resolver->setAllowedTypes('captcha', 'boolean');
+       }
+
        /**
         * Validate captcha
         *
        /**
         * Validate captcha
         *