vendor/dachcom-digital/formbuilder/src/FormBuilderBundle/Form/Type/HoneypotType.php line 12

Open in your IDE?
  1. <?php
  2. namespace FormBuilderBundle\Form\Type;
  3. use FormBuilderBundle\Configuration\Configuration;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\TextType;
  6. use Symfony\Component\OptionsResolver\OptionsResolver;
  7. use Symfony\Component\Validator\Constraint;
  8. use Symfony\Component\Validator\Constraints\Blank;
  9. class HoneypotType extends AbstractType
  10. {
  11.     protected Configuration $configuration;
  12.     public function __construct(Configuration $configuration)
  13.     {
  14.         $this->configuration $configuration;
  15.     }
  16.     public function configureOptions(OptionsResolver $resolver): void
  17.     {
  18.         $config $this->configuration->getConfig('spam_protection');
  19.         $honeyPotConfig $config['honeypot'];
  20.         $attributes = [
  21.             'autocomplete' => 'off',
  22.             'tabindex'     => -1,
  23.             'style'        => $honeyPotConfig['enable_inline_style'] === true 'position: absolute; left: -500%; top: -500%;' ''
  24.         ];
  25.         if ($honeyPotConfig['enable_role_attribute'] === true) {
  26.             $attributes['role'] = 'presentation';
  27.         }
  28.         $resolver->setDefaults([
  29.             'required'       => false,
  30.             'mapped'         => false,
  31.             'data'           => '',
  32.             'attr'           => $attributes,
  33.             'constraints'    => [
  34.                 new Blank(
  35.                     [
  36.                         'groups'  => [
  37.                             Constraint::DEFAULT_GROUP,
  38.                             'honeypot'
  39.                         ],
  40.                         'message' => 'An error has occurred, please refresh the page and try again.',
  41.                     ]
  42.                 )
  43.             ],
  44.             'error_bubbling' => true,
  45.             'label'          => false
  46.         ]);
  47.     }
  48.     public function getParent(): string
  49.     {
  50.         return TextType::class;
  51.     }
  52.     public function getBlockPrefix(): string
  53.     {
  54.         return 'form_builder_honeypot';
  55.     }
  56. }