-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added PreviousStepInvalidEvent and PreviousStepInvalidEventListener
- Loading branch information
Showing
9 changed files
with
172 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Craue\FormFlowBundle\Event; | ||
|
||
use Craue\FormFlowBundle\Form\FormFlowInterface; | ||
use Symfony\Component\Form\FormInterface; | ||
|
||
/** | ||
* Is called once if revalidating previous steps failed. | ||
* | ||
* @author Christian Raue <christian.raue@gmail.com> | ||
* @copyright 2011-2014 Christian Raue | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
class PreviousStepInvalidEvent extends FormFlowEvent { | ||
|
||
/** | ||
* @var integer | ||
*/ | ||
protected $invalidStepNumber; | ||
|
||
/** | ||
* @var FormInterface | ||
*/ | ||
protected $currentStepForm; | ||
|
||
/** | ||
* @param FormFlowInterface $flow | ||
* @param FormInterface $currentStepForm | ||
* @param integer $invalidStepNumber | ||
*/ | ||
public function __construct(FormFlowInterface $flow, FormInterface $currentStepForm, $invalidStepNumber) { | ||
$this->flow = $flow; | ||
$this->currentStepForm = $currentStepForm; | ||
$this->invalidStepNumber = $invalidStepNumber; | ||
} | ||
|
||
/** | ||
* @return FormInterface | ||
*/ | ||
public function getCurrentStepForm() { | ||
return $this->currentStepForm; | ||
} | ||
|
||
/** | ||
* @return integer | ||
*/ | ||
public function getInvalidStepNumber() { | ||
return $this->invalidStepNumber; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Craue\FormFlowBundle\EventListener; | ||
|
||
use Craue\FormFlowBundle\Event\PreviousStepInvalidEvent; | ||
use Symfony\Component\Form\FormError; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
|
||
/** | ||
* Adds a validation error to the current step's form if revalidating previous steps failed. | ||
* | ||
* @author Christian Raue <christian.raue@gmail.com> | ||
* @copyright 2011-2014 Christian Raue | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
class PreviousStepInvalidEventListener { | ||
|
||
/** | ||
* @var TranslatorInterface | ||
*/ | ||
protected $translator; | ||
|
||
public function setTranslator(TranslatorInterface $translator) { | ||
$this->translator = $translator; | ||
} | ||
|
||
public function onPreviousStepInvalid(PreviousStepInvalidEvent $event) { | ||
$event->getCurrentStepForm()->addError($this->getPreviousStepInvalidFormError($event->getInvalidStepNumber())); | ||
} | ||
|
||
/** | ||
* @param integer $stepNumber | ||
* @return FormError | ||
*/ | ||
protected function getPreviousStepInvalidFormError($stepNumber) { | ||
$messageId = 'craueFormFlow.previousStepInvalid'; | ||
$messageParameters = array('%stepNumber%' => $stepNumber); | ||
|
||
if (version_compare(Kernel::VERSION, '2.2', '>=')) { | ||
return new FormError($this->translator->trans($messageId, $messageParameters, 'validators')); | ||
} | ||
|
||
// TODO remove as soon as Symfony >= 2.2 is required | ||
return new FormError($messageId, $messageParameters); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters