create first class form and adapt config for injecting form process in

Smarty
This commit is contained in:
Manuel Raynaud
2013-06-24 10:34:34 +02:00
parent 2edc71e9c3
commit f699686d13
3 changed files with 64 additions and 4 deletions

View File

@@ -21,6 +21,10 @@
-->
</templateDirectives>
<forms>
<form name="thelia.customer.creation" class="Thelia\Form\CustomerCreation"/>
</forms>
<commands>
<command class="Thelia\Command\CacheClear"/>
@@ -72,6 +76,15 @@
</call>
</service>
<service id="smart.plugin.form" class="Thelia\Core\Template\Smarty\Plugins\Form" scope="request">
<tag name="thelia.parser.register_plugin"/>
<argument type="service" id="request"/>
<call method="setFormDefinition">
<argument>%thelia.parser.forms%</argument>
</call>
</service>
<service id="smarty.plugin.translation" class="Thelia\Core\Template\Smarty\Plugins\Translation" >
<tag name="thelia.parser.register_plugin"/>
</service>

View File

@@ -29,6 +29,7 @@ use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\SimpleXMLElement;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
@@ -62,6 +63,8 @@ class XmlFileLoader extends FileLoader
$this->parseCommands($xml);
$this->parseForms($xml);
$this->parseDefinitions($xml, $path);
}
@@ -72,7 +75,7 @@ class XmlFileLoader extends FileLoader
}
try {
$commandConfig = $this->container->getParameter("command.definition");
} catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) {
} catch (ParameterNotFoundException $e) {
$commandConfig = array();
}
@@ -110,7 +113,7 @@ class XmlFileLoader extends FileLoader
}
try {
$loopConfig = $this->container->getParameter("Thelia.parser.loops");
} catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) {
} catch (ParameterNotFoundException $e) {
$loopConfig = array();
}
@@ -121,6 +124,25 @@ class XmlFileLoader extends FileLoader
$this->container->setParameter("Thelia.parser.loops", $loopConfig);
}
protected function parseForms(SimpleXMLElement $xml)
{
if (false === $forms = $xml->xpath('//config:forms/config:form')) {
return;
}
try {
$formConfig = $this->container->getParameter("Thelia.parser.forms");
} catch (ParameterNotFoundException $e) {
$formConfig = array();
}
foreach ($forms as $form) {
$formConfig[$form->getAttributeAsPhp('name')] = $formConfig->getAttributeAsPhp('class');
}
$this->container->setParameter('Thelia.parser.forms', $formConfig);
}
/**
* parse Filters property
*
@@ -133,7 +155,7 @@ class XmlFileLoader extends FileLoader
}
try {
$filterConfig = $this->container->getParameter("Thelia.parser.filters");
} catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) {
} catch (ParameterNotFoundException $e) {
$filterConfig = array();
}
@@ -156,7 +178,7 @@ class XmlFileLoader extends FileLoader
}
try {
$baseParamConfig = $this->container->getParameter("Thelia.parser.templateDirectives");
} catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) {
} catch (ParameterNotFoundException $e) {
$baseParamConfig = array();
}

View File

@@ -0,0 +1,25 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
class CustomerCreation {
}