vendor/craue/formflow-bundle/EventListener/PreviousStepInvalidEventListener.php line 20

Open in your IDE?
  1. <?php
  2. namespace Craue\FormFlowBundle\EventListener;
  3. use Craue\FormFlowBundle\Event\PreviousStepInvalidEvent;
  4. use Symfony\Component\Form\FormError;
  5. use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
  6. use Symfony\Contracts\Translation\TranslatorInterface;
  7. /**
  8.  * @internal
  9.  */
  10. abstract class BasePreviousStepInvalidEventListener {
  11.     /**
  12.      * @var TranslatorInterface|LegacyTranslatorInterface
  13.      */
  14.     protected $translator;
  15.     public function onPreviousStepInvalid(PreviousStepInvalidEvent $event) {
  16.         $event->getCurrentStepForm()->addError($this->getPreviousStepInvalidFormError($event->getInvalidStepNumber()));
  17.     }
  18.     /**
  19.      * @param int $stepNumber
  20.      * @return FormError
  21.      */
  22.     protected function getPreviousStepInvalidFormError($stepNumber) {
  23.         $messageId 'craueFormFlow.previousStepInvalid';
  24.         $messageParameters = ['%stepNumber%' => $stepNumber];
  25.         return new FormError($this->translator->trans($messageId$messageParameters'validators'), $messageId$messageParameters);
  26.     }
  27. }
  28. // TODO revert to one clean class definition as soon as Symfony >= 4.2 is required
  29. if (!interface_exists(LegacyTranslatorInterface::class)) {
  30.     /**
  31.      * Adds a validation error to the current step's form if revalidating previous steps failed.
  32.      *
  33.      * @author Christian Raue <christian.raue@gmail.com>
  34.      * @copyright 2011-2020 Christian Raue
  35.      * @license http://opensource.org/licenses/mit-license.php MIT License
  36.      */
  37.     class PreviousStepInvalidEventListener extends BasePreviousStepInvalidEventListener {
  38.         public function setTranslator(TranslatorInterface $translator) {
  39.             $this->translator $translator;
  40.         }
  41.     }
  42. } else {
  43.     /**
  44.      * Adds a validation error to the current step's form if revalidating previous steps failed.
  45.      *
  46.      * @author Christian Raue <christian.raue@gmail.com>
  47.      * @copyright 2011-2020 Christian Raue
  48.      * @license http://opensource.org/licenses/mit-license.php MIT License
  49.      */
  50.     class PreviousStepInvalidEventListener extends BasePreviousStepInvalidEventListener {
  51.         public function setTranslator(LegacyTranslatorInterface $translator) {
  52.             $this->translator $translator;
  53.         }
  54.     }
  55. }