Merge branch 'master' into loops
Conflicts: core/lib/Thelia/Core/Template/Loop/Category.php core/lib/Thelia/Core/Template/Loop/FeatureValue.php core/lib/Thelia/Core/Template/Loop/Folder.php core/lib/Thelia/Core/Template/Loop/Product.php core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php install/faker.php
This commit is contained in:
83
documentation/api/files/Action/BaseAction.php.txt
Normal file → Executable file
83
documentation/api/files/Action/BaseAction.php.txt
Normal file → Executable file
@@ -22,44 +22,60 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Thelia\Form\CategoryDeletionForm;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Action\Exception\FormValidationException;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
abstract class BaseAction
|
||||
class BaseAction
|
||||
{
|
||||
protected function validateForm(BaseForm $aBaseForm, $expectedMethod = null)
|
||||
{
|
||||
$form = $aBaseForm->getForm();
|
||||
|
||||
if ($aBaseForm->getRequest()->isMethod($expectedMethod)) {
|
||||
/**
|
||||
* @var The container
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
$form->bind($aBaseForm->getRequest());
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
if ($form->isValid()) {
|
||||
/**
|
||||
* Validate a BaseForm
|
||||
*
|
||||
* @param BaseForm $aBaseForm the form
|
||||
* @param string $expectedMethod the expected method, POST or GET, or null for any of them
|
||||
* @throws FormValidationException is the form contains error, or the method is not the right one
|
||||
* @return \Symfony\Component\Form\Form Form the symfony form object
|
||||
*/
|
||||
protected function validateForm(BaseForm $aBaseForm, $expectedMethod = null)
|
||||
{
|
||||
$form = $aBaseForm->getForm();
|
||||
|
||||
return $form;
|
||||
}
|
||||
else {
|
||||
throw new FormValidationException("Missing or invalid data");
|
||||
if ($expectedMethod == null || $aBaseForm->getRequest()->isMethod($expectedMethod)) {
|
||||
|
||||
$form->bind($aBaseForm->getRequest());
|
||||
|
||||
if ($form->isValid()) {
|
||||
return $form;
|
||||
} else {
|
||||
throw new FormValidationException("Missing or invalid data");
|
||||
}
|
||||
} else {
|
||||
throw new FormValidationException(sprintf("Wrong form method, %s expected.", $expectedMethod));
|
||||
}
|
||||
else {
|
||||
throw new FormValidationException(sprintf("Wrong form method, %s expected.", $expectedMethod));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param BaseForm $aBaseForm
|
||||
* @param string $error_message
|
||||
* @param ActionEvent $event
|
||||
*/
|
||||
protected function propagateFormError(BaseForm $aBaseForm, $error_message, ActionEvent $event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Propagate a form error in the action event
|
||||
*
|
||||
* @param BaseForm $aBaseForm the form
|
||||
* @param string $error_message an error message that may be displayed to the customer
|
||||
* @param ActionEvent $event the action event
|
||||
*/
|
||||
protected function propagateFormError(BaseForm $aBaseForm, $error_message, ActionEvent $event)
|
||||
{
|
||||
// The form has an error
|
||||
$aBaseForm->setError(true);
|
||||
$aBaseForm->setErrorMessage($error_message);
|
||||
@@ -69,14 +85,17 @@ abstract class BaseAction
|
||||
|
||||
// Stop event propagation
|
||||
$event->stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
protected function redirect($url, $status = 302)
|
||||
/**
|
||||
* Return the event dispatcher,
|
||||
*
|
||||
* @return \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||
*/
|
||||
public function getDispatcher()
|
||||
{
|
||||
$response = new RedirectResponse($url, $status);
|
||||
|
||||
$response->send();
|
||||
exit;
|
||||
return $this->container->get('event_dispatcher');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user