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

Open in your IDE?
  1. <?php
  2. namespace Craue\FormFlowBundle\EventListener;
  3. use Craue\FormFlowBundle\Event\PreviousStepInvalidEvent;
  4. use Symfony\Component\Form\FormError;
  5. /**
  6. * Adds a validation error to the current step's form if revalidating previous steps failed.
  7. *
  8. * @author Christian Raue <christian.raue@gmail.com>
  9. * @copyright 2011-2024 Christian Raue
  10. * @license http://opensource.org/licenses/mit-license.php MIT License
  11. */
  12. class PreviousStepInvalidEventListener {
  13. use EventListenerWithTranslatorTrait;
  14. public function onPreviousStepInvalid(PreviousStepInvalidEvent $event) {
  15. $event->getCurrentStepForm()->addError($this->getPreviousStepInvalidFormError($event->getInvalidStepNumber()));
  16. }
  17. /**
  18. * @param int $stepNumber
  19. * @return FormError
  20. */
  21. protected function getPreviousStepInvalidFormError($stepNumber) {
  22. $messageId = 'craueFormFlow.previousStepInvalid';
  23. $messageParameters = ['%stepNumber%' => $stepNumber];
  24. return new FormError($this->translator->trans($messageId, $messageParameters, 'validators'), $messageId, $messageParameters);
  25. }
  26. }