fix cs
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -27,11 +27,12 @@ use Thelia\Tools\URL;
|
||||
class TranslationsController extends BaseAdminController
|
||||
{
|
||||
/**
|
||||
* @param string $item_name the modume code
|
||||
* @return Module the module object
|
||||
* @param string $item_name the modume code
|
||||
* @return Module the module object
|
||||
* @throws \InvalidArgumentException if module was not found
|
||||
*/
|
||||
protected function getModule($item_name) {
|
||||
protected function getModule($item_name)
|
||||
{
|
||||
if (null !== $module = ModuleQuery::create()->findPk($item_name))
|
||||
return $module;
|
||||
|
||||
@@ -40,8 +41,8 @@ class TranslationsController extends BaseAdminController
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
protected function getModuleTemplateNames(Module $module, $template_type) {
|
||||
protected function getModuleTemplateNames(Module $module, $template_type)
|
||||
{
|
||||
$templates =
|
||||
TemplateHelper::getInstance()->getList(
|
||||
$template_type,
|
||||
@@ -96,14 +97,12 @@ class TranslationsController extends BaseAdminController
|
||||
$domain = $module->getTranslationDomain();
|
||||
$i18n_directory = $module->getAbsoluteI18nPath();
|
||||
$walkMode = TemplateHelper::WALK_MODE_PHP;
|
||||
}
|
||||
else if ($module_part == 'admin-includes') {
|
||||
} elseif ($module_part == 'admin-includes') {
|
||||
$directory = $module->getAbsoluteAdminIncludesPath();
|
||||
$domain = $module->getAdminIncludesTranslationDomain();
|
||||
$i18n_directory = $module->getAbsoluteAdminIncludesI18nPath();
|
||||
$walkMode = TemplateHelper::WALK_MODE_TEMPLATE;
|
||||
}
|
||||
else if (! empty($module_part)) {
|
||||
} elseif (! empty($module_part)) {
|
||||
// Front or back office template, form of $module_part is [bo|fo].subdir-name
|
||||
list($type, $subdir) = explode('.', $module_part);
|
||||
|
||||
@@ -111,13 +110,11 @@ class TranslationsController extends BaseAdminController
|
||||
$directory = $module->getAbsoluteBackOfficeTemplatePath($subdir);
|
||||
$domain = $module->getBackOfficeTemplateTranslationDomain($subdir);
|
||||
$i18n_directory = $module->getAbsoluteBackOfficeI18nTemplatePath($subdir);
|
||||
}
|
||||
else if ($type == 'fo') {
|
||||
} elseif ($type == 'fo') {
|
||||
$directory = $module->getAbsoluteFrontOfficeTemplatePath($subdir);
|
||||
$domain = $module->getFrontOfficeTemplateTranslationDomain($subdir);
|
||||
$i18n_directory = $module->getAbsoluteFrontOfficeI18nTemplatePath($subdir);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new \InvalidArgumentException("Undefined module template type: '$type'.");
|
||||
}
|
||||
|
||||
@@ -171,7 +168,7 @@ class TranslationsController extends BaseAdminController
|
||||
|
||||
if ($template) {
|
||||
$directory = $template->getAbsolutePath();
|
||||
|
||||
|
||||
$i18n_directory = $template->getAbsoluteI18nPath();
|
||||
|
||||
$domain = $template->getTranslationDomain();
|
||||
|
||||
@@ -132,10 +132,10 @@ abstract class BaseLoop
|
||||
/**
|
||||
* Provides a getter to loop parameter values
|
||||
*
|
||||
* @param string $name the method name (only getArgname is supported)
|
||||
* @param mixed $arguments this parameter is ignored
|
||||
* @param string $name the method name (only getArgname is supported)
|
||||
* @param mixed $arguments this parameter is ignored
|
||||
*
|
||||
* @return mixed the argument value
|
||||
* @return mixed the argument value
|
||||
* @throws \InvalidArgumentException if the parameter is unknown or the method name is not supported.
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
@@ -230,7 +230,7 @@ abstract class BaseLoop
|
||||
*
|
||||
* @param string $argumentName the argument name
|
||||
*
|
||||
* @return Argument the loop argument.
|
||||
* @return Argument the loop argument.
|
||||
* @throws \InvalidArgumentException if argument is not found in loop argument list
|
||||
*/
|
||||
protected function getArg($argumentName)
|
||||
@@ -251,7 +251,7 @@ abstract class BaseLoop
|
||||
* @param string $argumentName the argument name
|
||||
*
|
||||
* @throws \InvalidArgumentException if argument is not found in loop argument list
|
||||
* @return mixed the loop argument value
|
||||
* @return mixed the loop argument value
|
||||
*/
|
||||
protected function getArgValue($argumentName)
|
||||
{
|
||||
@@ -263,7 +263,7 @@ abstract class BaseLoop
|
||||
* @param PropelModelPager $pagination the pagination part
|
||||
*
|
||||
* @return array|PropelModelPager|ObjectCollection
|
||||
* @throws \InvalidArgumentException if the search mode is undefined.
|
||||
* @throws \InvalidArgumentException if the search mode is undefined.
|
||||
*/
|
||||
protected function search(ModelCriteria $search, &$pagination = null)
|
||||
{
|
||||
@@ -356,7 +356,7 @@ abstract class BaseLoop
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ModelCriteria $search
|
||||
* @param ModelCriteria $search
|
||||
* @param PropelModelPager $pagination
|
||||
*
|
||||
* @return array|PropelModelPager
|
||||
@@ -536,4 +536,4 @@ abstract class BaseLoop
|
||||
*/
|
||||
abstract protected function getArgDefinitions();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,4 +94,4 @@ class Delivery extends BaseSpecificModule
|
||||
{
|
||||
return BaseModule::DELIVERY_MODULE_TYPE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class TheliaLoop extends AbstractSmartyPlugin
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $loopName
|
||||
* @param string $loopName
|
||||
* @return PropelModelPager
|
||||
* @throws \InvalidArgumentException if no pagination was found for loop
|
||||
*/
|
||||
@@ -77,10 +77,10 @@ class TheliaLoop extends AbstractSmartyPlugin
|
||||
/**
|
||||
* Process the count function: executes a loop and return the number of items found
|
||||
*
|
||||
* @param array $params parameters array
|
||||
* @param array $params parameters array
|
||||
* @param \Smarty_Internal_Template $template
|
||||
*
|
||||
* @return int the item count
|
||||
* @return int the item count
|
||||
* @throws \InvalidArgumentException if a parameter is missing
|
||||
*
|
||||
*/
|
||||
@@ -104,10 +104,10 @@ class TheliaLoop extends AbstractSmartyPlugin
|
||||
/**
|
||||
* Process {loop name="loop name" type="loop type" ... } ... {/loop} block
|
||||
*
|
||||
* @param array $params
|
||||
* @param string $content
|
||||
* @param \Smarty_Internal_Template $template
|
||||
* @param boolean $repeat
|
||||
* @param array $params
|
||||
* @param string $content
|
||||
* @param \Smarty_Internal_Template $template
|
||||
* @param boolean $repeat
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
@@ -209,11 +209,11 @@ class TheliaLoop extends AbstractSmartyPlugin
|
||||
/**
|
||||
* Process {elseloop rel="loopname"} ... {/elseloop} block
|
||||
*
|
||||
* @param array $params loop parameters
|
||||
* @param string $content loop text content
|
||||
* @param array $params loop parameters
|
||||
* @param string $content loop text content
|
||||
* @param \Smarty_Internal_Template $template the Smarty object
|
||||
* @param boolean $repeat repeat indicator (see Smarty doc.)
|
||||
* @return string the loop output
|
||||
* @param boolean $repeat repeat indicator (see Smarty doc.)
|
||||
* @return string the loop output
|
||||
*/
|
||||
public function theliaElseloop($params, $content, /** @noinspection PhpUnusedParameterInspection */ $template, &$repeat)
|
||||
{
|
||||
@@ -228,11 +228,11 @@ class TheliaLoop extends AbstractSmartyPlugin
|
||||
/**
|
||||
* Process {ifloop rel="loopname"} ... {/ifloop} block
|
||||
*
|
||||
* @param array $params loop parameters
|
||||
* @param string $content loop text content
|
||||
* @param array $params loop parameters
|
||||
* @param string $content loop text content
|
||||
* @param \Smarty_Internal_Template $template the Smarty object
|
||||
* @param boolean $repeat repeat indicator (see Smarty doc.)
|
||||
* @return string the loop output
|
||||
* @param boolean $repeat repeat indicator (see Smarty doc.)
|
||||
* @return string the loop output
|
||||
*/
|
||||
public function theliaIfLoop($params, $content, /** @noinspection PhpUnusedParameterInspection */ $template, &$repeat)
|
||||
{
|
||||
@@ -247,11 +247,11 @@ class TheliaLoop extends AbstractSmartyPlugin
|
||||
/**
|
||||
* Process {pageloop rel="loopname"} ... {/pageloop} block
|
||||
*
|
||||
* @param array $params loop parameters
|
||||
* @param string $content loop text content
|
||||
* @param array $params loop parameters
|
||||
* @param string $content loop text content
|
||||
* @param \Smarty_Internal_Template $template the Smarty object
|
||||
* @param boolean $repeat repeat indicator (see Smarty doc.)
|
||||
* @return string the loop output
|
||||
* @param boolean $repeat repeat indicator (see Smarty doc.)
|
||||
* @return string the loop output
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function theliaPageLoop($params, $content, $template, &$repeat)
|
||||
@@ -337,9 +337,9 @@ class TheliaLoop extends AbstractSmartyPlugin
|
||||
* Check if a loop has returned results. The loop shoud have been executed before, or an
|
||||
* InvalidArgumentException is thrown
|
||||
*
|
||||
* @param array $params
|
||||
* @param array $params
|
||||
*
|
||||
* @return boolean true if the loop is empty
|
||||
* @return boolean true if the loop is empty
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function checkEmptyLoop($params)
|
||||
|
||||
@@ -29,7 +29,7 @@ class Translation extends AbstractSmartyPlugin
|
||||
/**
|
||||
* Set the default translation domain
|
||||
*
|
||||
* @param array $params
|
||||
* @param array $params
|
||||
* @param \Smarty_Internal_Template $smarty
|
||||
* @return string
|
||||
*/
|
||||
@@ -41,7 +41,7 @@ class Translation extends AbstractSmartyPlugin
|
||||
/**
|
||||
* Process translate function
|
||||
*
|
||||
* @param array $params
|
||||
* @param array $params
|
||||
* @param \Smarty_Internal_Template $smarty
|
||||
* @return string
|
||||
*/
|
||||
|
||||
@@ -242,6 +242,7 @@ class SmartyParser extends Smarty implements ParserInterface
|
||||
if (false === $this->templateExists($realTemplateName) || false === $this->checkTemplate($realTemplateName)) {
|
||||
throw new ResourceNotFoundException(Translator::getInstance()->trans("Template file %file cannot be found.", array('%file' => $realTemplateName)));
|
||||
}
|
||||
|
||||
return $this->internalRenderer('file', $realTemplateName, $parameters);
|
||||
|
||||
}
|
||||
|
||||
@@ -77,7 +77,8 @@ class TemplateDefinition
|
||||
}
|
||||
}
|
||||
|
||||
public function getTranslationDomain() {
|
||||
public function getTranslationDomain()
|
||||
{
|
||||
return $this->translationDomainPrefix . strtolower($this->getName());
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ class TemplateHelper
|
||||
/**
|
||||
* Return a list of existing templates for a given template type
|
||||
*
|
||||
* @param int $templateType the template type
|
||||
* @param int $templateType the template type
|
||||
* @param string the template base (module or core, default to core).
|
||||
* @return TemplateDefinition[] of \Thelia\Core\Template\TemplateDefinition
|
||||
*/
|
||||
@@ -126,8 +126,7 @@ class TemplateHelper
|
||||
|
||||
$list[] = new TemplateDefinition($file->getFilename(), $templateType);
|
||||
}
|
||||
}
|
||||
catch (\UnexpectedValueException $ex) {
|
||||
} catch (\UnexpectedValueException $ex) {
|
||||
// Ignore the exception and continue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ class Thelia extends Kernel
|
||||
$module->getAbsoluteTemplateBasePath()
|
||||
);
|
||||
|
||||
foreach($templates as $template) {
|
||||
foreach ($templates as $template) {
|
||||
$translationDirs[$module->getBackOfficeTemplateTranslationDomain($template->getName())] =
|
||||
$module->getAbsoluteBackOfficeI18nTemplatePath($template->getName());
|
||||
}
|
||||
@@ -229,7 +229,7 @@ class Thelia extends Kernel
|
||||
$module->getAbsoluteTemplateBasePath()
|
||||
);
|
||||
|
||||
foreach($templates as $template) {
|
||||
foreach ($templates as $template) {
|
||||
$translationDirs[$module->getFrontOfficeTemplateTranslationDomain($template->getName())] =
|
||||
$module->getAbsoluteFrontOfficeI18nTemplatePath($template->getName());
|
||||
}
|
||||
@@ -279,8 +279,7 @@ class Thelia extends Kernel
|
||||
|
||||
$translator->addMethodCall('addResource', array($format, (string) $file, $locale, $domain));
|
||||
}
|
||||
}
|
||||
catch (\InvalidArgumentException $ex) {
|
||||
} catch (\InvalidArgumentException $ex) {
|
||||
// Ignore missing I18n directories
|
||||
Tlog::getInstance()->addWarning("loadTranslation: missing $dir directory");
|
||||
}
|
||||
|
||||
@@ -13,224 +13,224 @@
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
|
||||
use Symfony\Component\Form\Forms;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;
|
||||
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
|
||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
/**
|
||||
* Base form class for creating form objects
|
||||
*
|
||||
* Class BaseForm
|
||||
* @package Thelia\Form
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
abstract class BaseForm
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\Form\FormFactoryInterface
|
||||
*/
|
||||
protected $formBuilder;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\Form\Form
|
||||
*/
|
||||
protected $form;
|
||||
|
||||
protected $request;
|
||||
|
||||
private $view = null;
|
||||
|
||||
/**
|
||||
* true if the form has an error, false otherwise.
|
||||
* @var boolean
|
||||
*/
|
||||
private $has_error = false;
|
||||
|
||||
/**
|
||||
* The form error message.
|
||||
* @var string
|
||||
*/
|
||||
private $error_message = '';
|
||||
|
||||
public function __construct(Request $request, $type= "form", $data = array(), $options = array())
|
||||
{
|
||||
$this->request = $request;
|
||||
|
||||
$validator = Validation::createValidatorBuilder();
|
||||
|
||||
if (!isset($options["attr"]["name"])) {
|
||||
$options["attr"]["thelia_name"] = $this->getName();
|
||||
}
|
||||
|
||||
$builder = Forms::createFormFactoryBuilder()
|
||||
->addExtension(new HttpFoundationExtension());
|
||||
if (!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) {
|
||||
$builder->addExtension(
|
||||
new CsrfExtension(
|
||||
new SessionCsrfProvider(
|
||||
$request->getSession(),
|
||||
isset($options["secret"]) ? $options["secret"] : ConfigQuery::read("form.secret", md5(__DIR__))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$translator = Translator::getInstance();
|
||||
|
||||
$validator
|
||||
->setTranslationDomain('validators')
|
||||
->setTranslator($translator);
|
||||
$this->formBuilder = $builder
|
||||
->addExtension(new ValidatorExtension($validator->getValidator()))
|
||||
->getFormFactory()
|
||||
->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options));
|
||||
;
|
||||
|
||||
$this->buildForm();
|
||||
|
||||
// If not already set, define the success_url field
|
||||
if (! $this->formBuilder->has('success_url')) {
|
||||
$this->formBuilder->add("success_url", "text");
|
||||
}
|
||||
|
||||
if (! $this->formBuilder->has('error_message')) {
|
||||
$this->formBuilder->add("error_message", "text");
|
||||
}
|
||||
|
||||
$this->form = $this->formBuilder->getForm();
|
||||
}
|
||||
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
protected function cleanOptions($options)
|
||||
{
|
||||
unset($options["csrf_protection"]);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute URL to redirect the user to if the form is successfully processed.
|
||||
*
|
||||
* @param string $default the default URL. If not given, the configured base URL is used.
|
||||
*
|
||||
* @return string an absolute URL
|
||||
*/
|
||||
public function getSuccessUrl($default = null)
|
||||
{
|
||||
$successUrl = $this->form->get('success_url')->getData();
|
||||
|
||||
if (empty($successUrl)) {
|
||||
|
||||
if ($default === null) $default = ConfigQuery::read('base_url', '/');
|
||||
|
||||
$successUrl = $default;
|
||||
}
|
||||
|
||||
return URL::getInstance()->absoluteUrl($successUrl);
|
||||
}
|
||||
|
||||
public function createView()
|
||||
{
|
||||
$this->view = $this->form->createView();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getView()
|
||||
{
|
||||
if ($this->view === null) throw new \LogicException("View was not created. Please call BaseForm::createView() first.");
|
||||
return $this->view;
|
||||
}
|
||||
|
||||
// -- Error and errro message ----------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the error status of the form.
|
||||
*
|
||||
* @param boolean $has_error
|
||||
*/
|
||||
public function setError($has_error = true)
|
||||
{
|
||||
$this->has_error = $has_error;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cuirrent error status of the form.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasError()
|
||||
{
|
||||
return $this->has_error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the error message related to global form error
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
public function setErrorMessage($message)
|
||||
{
|
||||
$this->setError(true);
|
||||
$this->error_message = $message;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the form error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorMessage()
|
||||
{
|
||||
return $this->error_message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\Form\Form
|
||||
*/
|
||||
public function getForm()
|
||||
{
|
||||
return $this->form;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* in this function you add all the fields you need for your Form.
|
||||
* Form this you have to call add method on $this->formBuilder attribute :
|
||||
*
|
||||
* $this->formBuilder->add("name", "text")
|
||||
* ->add("email", "email", array(
|
||||
* "attr" => array(
|
||||
* "class" => "field"
|
||||
* ),
|
||||
* "label" => "email",
|
||||
* "constraints" => array(
|
||||
* new \Symfony\Component\Validator\Constraints\NotBlank()
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* ->add('age', 'integer');
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
abstract protected function buildForm();
|
||||
|
||||
/**
|
||||
* @return string the name of you form. This name must be unique
|
||||
*/
|
||||
abstract public function getName();
|
||||
}
|
||||
use Symfony\Component\Form\Forms;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;
|
||||
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
|
||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
/**
|
||||
* Base form class for creating form objects
|
||||
*
|
||||
* Class BaseForm
|
||||
* @package Thelia\Form
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
abstract class BaseForm
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\Form\FormFactoryInterface
|
||||
*/
|
||||
protected $formBuilder;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\Form\Form
|
||||
*/
|
||||
protected $form;
|
||||
|
||||
protected $request;
|
||||
|
||||
private $view = null;
|
||||
|
||||
/**
|
||||
* true if the form has an error, false otherwise.
|
||||
* @var boolean
|
||||
*/
|
||||
private $has_error = false;
|
||||
|
||||
/**
|
||||
* The form error message.
|
||||
* @var string
|
||||
*/
|
||||
private $error_message = '';
|
||||
|
||||
public function __construct(Request $request, $type= "form", $data = array(), $options = array())
|
||||
{
|
||||
$this->request = $request;
|
||||
|
||||
$validator = Validation::createValidatorBuilder();
|
||||
|
||||
if (!isset($options["attr"]["name"])) {
|
||||
$options["attr"]["thelia_name"] = $this->getName();
|
||||
}
|
||||
|
||||
$builder = Forms::createFormFactoryBuilder()
|
||||
->addExtension(new HttpFoundationExtension());
|
||||
if (!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) {
|
||||
$builder->addExtension(
|
||||
new CsrfExtension(
|
||||
new SessionCsrfProvider(
|
||||
$request->getSession(),
|
||||
isset($options["secret"]) ? $options["secret"] : ConfigQuery::read("form.secret", md5(__DIR__))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$translator = Translator::getInstance();
|
||||
|
||||
$validator
|
||||
->setTranslationDomain('validators')
|
||||
->setTranslator($translator);
|
||||
$this->formBuilder = $builder
|
||||
->addExtension(new ValidatorExtension($validator->getValidator()))
|
||||
->getFormFactory()
|
||||
->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options));
|
||||
;
|
||||
|
||||
$this->buildForm();
|
||||
|
||||
// If not already set, define the success_url field
|
||||
if (! $this->formBuilder->has('success_url')) {
|
||||
$this->formBuilder->add("success_url", "text");
|
||||
}
|
||||
|
||||
if (! $this->formBuilder->has('error_message')) {
|
||||
$this->formBuilder->add("error_message", "text");
|
||||
}
|
||||
|
||||
$this->form = $this->formBuilder->getForm();
|
||||
}
|
||||
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
protected function cleanOptions($options)
|
||||
{
|
||||
unset($options["csrf_protection"]);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute URL to redirect the user to if the form is successfully processed.
|
||||
*
|
||||
* @param string $default the default URL. If not given, the configured base URL is used.
|
||||
*
|
||||
* @return string an absolute URL
|
||||
*/
|
||||
public function getSuccessUrl($default = null)
|
||||
{
|
||||
$successUrl = $this->form->get('success_url')->getData();
|
||||
|
||||
if (empty($successUrl)) {
|
||||
|
||||
if ($default === null) $default = ConfigQuery::read('base_url', '/');
|
||||
|
||||
$successUrl = $default;
|
||||
}
|
||||
|
||||
return URL::getInstance()->absoluteUrl($successUrl);
|
||||
}
|
||||
|
||||
public function createView()
|
||||
{
|
||||
$this->view = $this->form->createView();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getView()
|
||||
{
|
||||
if ($this->view === null) throw new \LogicException("View was not created. Please call BaseForm::createView() first.");
|
||||
return $this->view;
|
||||
}
|
||||
|
||||
// -- Error and errro message ----------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the error status of the form.
|
||||
*
|
||||
* @param boolean $has_error
|
||||
*/
|
||||
public function setError($has_error = true)
|
||||
{
|
||||
$this->has_error = $has_error;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cuirrent error status of the form.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasError()
|
||||
{
|
||||
return $this->has_error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the error message related to global form error
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
public function setErrorMessage($message)
|
||||
{
|
||||
$this->setError(true);
|
||||
$this->error_message = $message;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the form error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorMessage()
|
||||
{
|
||||
return $this->error_message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\Form\Form
|
||||
*/
|
||||
public function getForm()
|
||||
{
|
||||
return $this->form;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* in this function you add all the fields you need for your Form.
|
||||
* Form this you have to call add method on $this->formBuilder attribute :
|
||||
*
|
||||
* $this->formBuilder->add("name", "text")
|
||||
* ->add("email", "email", array(
|
||||
* "attr" => array(
|
||||
* "class" => "field"
|
||||
* ),
|
||||
* "label" => "email",
|
||||
* "constraints" => array(
|
||||
* new \Symfony\Component\Validator\Constraints\NotBlank()
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* ->add('age', 'integer');
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
abstract protected function buildForm();
|
||||
|
||||
/**
|
||||
* @return string the name of you form. This name must be unique
|
||||
*/
|
||||
abstract public function getName();
|
||||
}
|
||||
|
||||
@@ -1,179 +1,182 @@
|
||||
<?php
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Thelia\Core\Template\TemplateDefinition;
|
||||
use Thelia\Model\Base\Module as BaseModule;
|
||||
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
class Module extends BaseModule
|
||||
{
|
||||
use ModelEventDispatcherTrait;
|
||||
|
||||
use PositionManagementTrait;
|
||||
|
||||
const ADMIN_INCLUDES_DIRECTORY_NAME = "AdminIncludes";
|
||||
|
||||
|
||||
public function postSave(ConnectionInterface $con = null)
|
||||
{
|
||||
ModuleQuery::resetActivated();
|
||||
}
|
||||
|
||||
public function getTranslationDomain() {
|
||||
return strtolower($this->getCode());
|
||||
}
|
||||
|
||||
public function getAdminIncludesTranslationDomain() {
|
||||
return $this->getTranslationDomain().'.ai';
|
||||
}
|
||||
|
||||
public function getAbsoluteBackOfficeTemplatePath($subdir)
|
||||
{
|
||||
return sprintf("%s".DS."%s".DS."%s",
|
||||
$this->getAbsoluteTemplateBasePath(),
|
||||
TemplateDefinition::BACK_OFFICE_SUBDIR,
|
||||
$subdir
|
||||
);
|
||||
}
|
||||
|
||||
public function getAbsoluteBackOfficeI18nTemplatePath($subdir)
|
||||
{
|
||||
return sprintf("%s".DS."%s".DS."%s",
|
||||
$this->getAbsoluteI18nPath(),
|
||||
TemplateDefinition::BACK_OFFICE_SUBDIR,
|
||||
$subdir
|
||||
);
|
||||
}
|
||||
|
||||
public function getBackOfficeTemplateTranslationDomain($templateName) {
|
||||
return $this->getTranslationDomain(). '.bo.' . $templateName;
|
||||
}
|
||||
|
||||
public function getAbsoluteFrontOfficeTemplatePath($subdir)
|
||||
{
|
||||
return sprintf("%s".DS."%s".DS."%s",
|
||||
$this->getAbsoluteTemplateBasePath(),
|
||||
TemplateDefinition::FRONT_OFFICE_SUBDIR,
|
||||
$subdir
|
||||
);
|
||||
}
|
||||
|
||||
public function getAbsoluteFrontOfficeI18nTemplatePath($subdir)
|
||||
{
|
||||
return sprintf("%s".DS."%s".DS."%s",
|
||||
$this->getAbsoluteI18nPath(),
|
||||
TemplateDefinition::FRONT_OFFICE_SUBDIR,
|
||||
$subdir
|
||||
);
|
||||
}
|
||||
|
||||
public function getFrontOfficeTemplateTranslationDomain($templateName) {
|
||||
return $this->getTranslationDomain(). '.fo.' . $templateName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's base directory path, relative to THELIA_MODULE_DIR
|
||||
*/
|
||||
public function getBaseDir()
|
||||
{
|
||||
return ucfirst($this->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's base directory path, relative to THELIA_MODULE_DIR
|
||||
*/
|
||||
public function getAbsoluteBaseDir()
|
||||
{
|
||||
return THELIA_MODULE_DIR . $this->getBaseDir();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's config directory path, relative to THELIA_MODULE_DIR
|
||||
*/
|
||||
public function getConfigPath()
|
||||
{
|
||||
return $this->getBaseDir() . DS . "Config";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's config absolute directory path
|
||||
*/
|
||||
public function getAbsoluteConfigPath()
|
||||
{
|
||||
return THELIA_MODULE_DIR . $this->getConfigPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's i18N directory path, relative to THELIA_MODULE_DIR
|
||||
*/
|
||||
public function getI18nPath()
|
||||
{
|
||||
return $this->getBaseDir() . DS . "I18n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's i18N absolute directory path
|
||||
*/
|
||||
public function getAbsoluteI18nPath()
|
||||
{
|
||||
return THELIA_MODULE_DIR . $this->getI18nPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's AdminIncludes absolute directory path
|
||||
*/
|
||||
public function getAbsoluteAdminIncludesPath()
|
||||
{
|
||||
return $this->getAbsoluteBaseDir() . DS . self::ADMIN_INCLUDES_DIRECTORY_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's AdminIncludes i18N absolute directory path
|
||||
*/
|
||||
public function getAbsoluteAdminIncludesI18nPath()
|
||||
{
|
||||
return THELIA_MODULE_DIR . $this->getI18nPath() . DS . self::ADMIN_INCLUDES_DIRECTORY_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the absolute path to the module's template directory
|
||||
*
|
||||
* @return string a path
|
||||
*/
|
||||
public function getAbsoluteTemplateBasePath()
|
||||
{
|
||||
return $this->getAbsoluteBaseDir() . DS . 'templates';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the absolute path to one of the module's template directories
|
||||
*
|
||||
* @param int $templateSubdirName the name of the, probably one of TemplateDefinition::xxx_SUBDIR constants
|
||||
* @return string a path
|
||||
*/
|
||||
public function getAbsoluteTemplateDirectoryPath($templateSubdirName)
|
||||
{
|
||||
return $this->getAbsoluteTemplateBasePath() .DS. $templateSubdirName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate next position relative to module type
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query)
|
||||
{
|
||||
$query->filterByType($this->getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Thelia\Core\Template\TemplateDefinition;
|
||||
use Thelia\Model\Base\Module as BaseModule;
|
||||
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
class Module extends BaseModule
|
||||
{
|
||||
use ModelEventDispatcherTrait;
|
||||
|
||||
use PositionManagementTrait;
|
||||
|
||||
const ADMIN_INCLUDES_DIRECTORY_NAME = "AdminIncludes";
|
||||
|
||||
public function postSave(ConnectionInterface $con = null)
|
||||
{
|
||||
ModuleQuery::resetActivated();
|
||||
}
|
||||
|
||||
public function getTranslationDomain()
|
||||
{
|
||||
return strtolower($this->getCode());
|
||||
}
|
||||
|
||||
public function getAdminIncludesTranslationDomain()
|
||||
{
|
||||
return $this->getTranslationDomain().'.ai';
|
||||
}
|
||||
|
||||
public function getAbsoluteBackOfficeTemplatePath($subdir)
|
||||
{
|
||||
return sprintf("%s".DS."%s".DS."%s",
|
||||
$this->getAbsoluteTemplateBasePath(),
|
||||
TemplateDefinition::BACK_OFFICE_SUBDIR,
|
||||
$subdir
|
||||
);
|
||||
}
|
||||
|
||||
public function getAbsoluteBackOfficeI18nTemplatePath($subdir)
|
||||
{
|
||||
return sprintf("%s".DS."%s".DS."%s",
|
||||
$this->getAbsoluteI18nPath(),
|
||||
TemplateDefinition::BACK_OFFICE_SUBDIR,
|
||||
$subdir
|
||||
);
|
||||
}
|
||||
|
||||
public function getBackOfficeTemplateTranslationDomain($templateName)
|
||||
{
|
||||
return $this->getTranslationDomain(). '.bo.' . $templateName;
|
||||
}
|
||||
|
||||
public function getAbsoluteFrontOfficeTemplatePath($subdir)
|
||||
{
|
||||
return sprintf("%s".DS."%s".DS."%s",
|
||||
$this->getAbsoluteTemplateBasePath(),
|
||||
TemplateDefinition::FRONT_OFFICE_SUBDIR,
|
||||
$subdir
|
||||
);
|
||||
}
|
||||
|
||||
public function getAbsoluteFrontOfficeI18nTemplatePath($subdir)
|
||||
{
|
||||
return sprintf("%s".DS."%s".DS."%s",
|
||||
$this->getAbsoluteI18nPath(),
|
||||
TemplateDefinition::FRONT_OFFICE_SUBDIR,
|
||||
$subdir
|
||||
);
|
||||
}
|
||||
|
||||
public function getFrontOfficeTemplateTranslationDomain($templateName)
|
||||
{
|
||||
return $this->getTranslationDomain(). '.fo.' . $templateName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's base directory path, relative to THELIA_MODULE_DIR
|
||||
*/
|
||||
public function getBaseDir()
|
||||
{
|
||||
return ucfirst($this->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's base directory path, relative to THELIA_MODULE_DIR
|
||||
*/
|
||||
public function getAbsoluteBaseDir()
|
||||
{
|
||||
return THELIA_MODULE_DIR . $this->getBaseDir();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's config directory path, relative to THELIA_MODULE_DIR
|
||||
*/
|
||||
public function getConfigPath()
|
||||
{
|
||||
return $this->getBaseDir() . DS . "Config";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's config absolute directory path
|
||||
*/
|
||||
public function getAbsoluteConfigPath()
|
||||
{
|
||||
return THELIA_MODULE_DIR . $this->getConfigPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's i18N directory path, relative to THELIA_MODULE_DIR
|
||||
*/
|
||||
public function getI18nPath()
|
||||
{
|
||||
return $this->getBaseDir() . DS . "I18n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's i18N absolute directory path
|
||||
*/
|
||||
public function getAbsoluteI18nPath()
|
||||
{
|
||||
return THELIA_MODULE_DIR . $this->getI18nPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's AdminIncludes absolute directory path
|
||||
*/
|
||||
public function getAbsoluteAdminIncludesPath()
|
||||
{
|
||||
return $this->getAbsoluteBaseDir() . DS . self::ADMIN_INCLUDES_DIRECTORY_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's AdminIncludes i18N absolute directory path
|
||||
*/
|
||||
public function getAbsoluteAdminIncludesI18nPath()
|
||||
{
|
||||
return THELIA_MODULE_DIR . $this->getI18nPath() . DS . self::ADMIN_INCLUDES_DIRECTORY_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the absolute path to the module's template directory
|
||||
*
|
||||
* @return string a path
|
||||
*/
|
||||
public function getAbsoluteTemplateBasePath()
|
||||
{
|
||||
return $this->getAbsoluteBaseDir() . DS . 'templates';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the absolute path to one of the module's template directories
|
||||
*
|
||||
* @param int $templateSubdirName the name of the, probably one of TemplateDefinition::xxx_SUBDIR constants
|
||||
* @return string a path
|
||||
*/
|
||||
public function getAbsoluteTemplateDirectoryPath($templateSubdirName)
|
||||
{
|
||||
return $this->getAbsoluteTemplateBasePath() .DS. $templateSubdirName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate next position relative to module type
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query)
|
||||
{
|
||||
$query->filterByType($this->getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Module;
|
||||
|
||||
abstract class AbstractDeliveryModule extends BaseModule implements DeliveryModuleInterface
|
||||
{
|
||||
// This class is the base class for delivery modules
|
||||
// It may contains common methods in the future.
|
||||
}
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Module;
|
||||
|
||||
abstract class AbstractDeliveryModule extends BaseModule implements DeliveryModuleInterface
|
||||
{
|
||||
// This class is the base class for delivery modules
|
||||
// It may contains common methods in the future.
|
||||
}
|
||||
|
||||
@@ -92,4 +92,4 @@ abstract class AbstractPaymentModule extends BaseModule implements PaymentModule
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ class BaseModule extends ContainerAware implements BaseModuleInterface
|
||||
* Sets a module titles for various languages
|
||||
*
|
||||
* @param Module $module the module.
|
||||
* @param array $titles an associative array of locale => title_string
|
||||
* @param array $titles an associative array of locale => title_string
|
||||
*/
|
||||
public function setTitle(Module $module, $titles)
|
||||
{
|
||||
@@ -451,4 +451,4 @@ class BaseModule extends ContainerAware implements BaseModuleInterface
|
||||
{
|
||||
// Override this method to do something useful.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ interface DeliveryModuleInterface extends BaseModuleInterface
|
||||
*
|
||||
* @param Country $country the country to deliver to.
|
||||
*
|
||||
* @return float the delivery price
|
||||
* @return float the delivery price
|
||||
* @throws DeliveryException if the postage price cannot be calculated.
|
||||
*/
|
||||
public function getPostage(Country $country);
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Module\Exception;
|
||||
|
||||
class DeliveryException extends \RuntimeException
|
||||
{
|
||||
}
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Module\Exception;
|
||||
|
||||
class DeliveryException extends \RuntimeException
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user