vendor/pimcore/portal-engine/src/Form/RecoverPasswordForm.php line 31

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under following license:
  6.  * - Pimcore Commercial License (PCL)
  7.  *
  8.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  9.  *  @license    http://www.pimcore.org/license     PCL
  10.  */
  11. namespace Pimcore\Bundle\PortalEngineBundle\Form;
  12. use Pimcore\Bundle\PortalEngineBundle\Event\Auth\LoginFieldTypeEvent;
  13. use Pimcore\Model\DataObject\ClassDefinition;
  14. use Pimcore\Model\DataObject\PortalUser;
  15. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  16. use Symfony\Component\Form\AbstractType;
  17. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  18. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  19. use Symfony\Component\Form\Extension\Core\Type\TextType;
  20. use Symfony\Component\Form\FormBuilderInterface;
  21. use Symfony\Contracts\Translation\TranslatorInterface;
  22. /**
  23.  * Class RecoverPasswordForm
  24.  *
  25.  * @package Pimcore\Bundle\PortalEngineBundle\Form
  26.  */
  27. class RecoverPasswordForm extends AbstractType
  28. {
  29.     /**
  30.      * @var TranslatorInterface
  31.      */
  32.     private $translator;
  33.     /**
  34.      * @var array
  35.      */
  36.     private $fields;
  37.     /**
  38.      * @var EventDispatcherInterface
  39.      */
  40.     private $eventDispatcher;
  41.     /**
  42.      * RecoverPasswordForm constructor.
  43.      *
  44.      * @param EventDispatcherInterface $eventDispatcher
  45.      * @param TranslatorInterface $translator
  46.      * @param array $fields
  47.      */
  48.     public function __construct(EventDispatcherInterface $eventDispatcherTranslatorInterface $translator, array $fields)
  49.     {
  50.         $this->eventDispatcher $eventDispatcher;
  51.         $this->fields $fields;
  52.         $this->translator $translator;
  53.     }
  54.     /**
  55.      * @param FormBuilderInterface $builder
  56.      * @param array $options
  57.      */
  58.     public function buildForm(FormBuilderInterface $builder, array $options)
  59.     {
  60.         $event = new LoginFieldTypeEvent();
  61.         $this->eventDispatcher->dispatch($event);
  62.         if ($event->getUseEmailField() && $this->fields === ['email']) {
  63.             $builder
  64.                 ->add(
  65.                     'userIdentifier',
  66.                     EmailType::class,
  67.                     [
  68.                         'required' => true,
  69.                         'label' => 'portal-engine.auth.form_label_email',
  70.                         'attr' => [
  71.                             'autofocus' => true
  72.                         ]
  73.                     ]
  74.                 );
  75.         } else {
  76.             $classDefinition ClassDefinition::getById((string) PortalUser::classId());
  77.             $fieldLabels = [];
  78.             foreach ($this->fields as $fieldName) {
  79.                 $fieldDefinition $classDefinition->getFieldDefinition($fieldName);
  80.                 $fieldTitle $fieldDefinition->getTitle();
  81.                 $fieldLabels[] = $this->translator->trans($fieldTitle, [], 'admin');
  82.             }
  83.             $builder
  84.                 ->add(
  85.                     'userIdentifier',
  86.                     TextType::class,
  87.                     [
  88.                         'required' => true,
  89.                         'label' => implode(' / '$fieldLabels),
  90.                         'attr' => [
  91.                             'autofocus' => true
  92.                         ]
  93.                     ]
  94.                 );
  95.         }
  96.         $builder->add(
  97.             'submit',
  98.             SubmitType::class,
  99.             [
  100.                 'label' => 'portal-engine.auth.recover_password_button',
  101.             ]
  102.         );
  103.     }
  104. }