- public function __construct(ImageUtil $image, SluggerUtil $slugger, TranslatorInterface $translator) {
- //Set image
- $this->image = $image;
+ public function buildForm(FormBuilderInterface $builder, array $options): void {
+ //With image, slugger and translator
+ if (!empty($options['captcha']) && $this->image !== null && $this->slugger !== null && $this->translator !== null) {
+ //Set captcha
+ $captcha = $this->image->getCaptcha((new \DateTime('-1 year'))->getTimestamp());
+
+ //Add captcha token
+ $builder->add('_captcha_token', HiddenType::class, ['data' => $captcha['token'], 'empty_data' => $captcha['token'], 'mapped' => false]);