Skip to content

Commit

Permalink
[Form] Add the FormHelper configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Jun 22, 2011
1 parent a43fad4 commit 5d46e63
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 6 deletions.
Expand Up @@ -205,6 +205,23 @@ private function addTemplatingSection(ArrayNodeDefinition $rootNode)
->children()
->scalarNode('assets_version')->defaultValue(null)->end()
->scalarNode('assets_version_format')->defaultValue(null)->end()
->arrayNode('form')
->addDefaultsIfNotSet()
->fixXmlConfig('resource')
->children()
->arrayNode('resources')
->addDefaultsIfNotSet()
->defaultValue(array('FrameworkBundle:Form'))
->validate()
->ifTrue(function($v) {return !in_array('FrameworkBundle:Form', $v); })
->then(function($v){
return array_merge(array('FrameworkBundle:Form'), $v);
})
->end()
->prototype('scalar')->end()
->end()
->end()
->end()
->end()
->fixXmlConfig('assets_base_url')
->children()
Expand Down
Expand Up @@ -314,6 +314,7 @@ private function registerTemplatingConfiguration(array $config, $ide, ContainerB
);

$container->setParameter('templating.helper.code.file_link_format', str_replace('%', '%%', isset($links[$ide]) ? $links[$ide] : $ide));
$container->setParameter('templating.helper.form.resources', $config['form']['resources']);

if ($container->getParameter('kernel.debug')) {
$loader->load('templating_debug.xml');
Expand Down
Expand Up @@ -90,13 +90,20 @@
<xsd:element name="engine" type="xsd:string" minOccurs="1" maxOccurs="unbounded" />
<xsd:element name="assets-base-url" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="package" type="package" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="form" type="form-resources" minOccurs="0" maxOccurs="1" />
</xsd:sequence>

<xsd:attribute name="assets-version" type="xsd:string" />
<xsd:attribute name="assets-version-format" type="xsd:string" />
<xsd:attribute name="cache" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="form-resources">
<xsd:choice minOccurs="1" maxOccurs="unbounded">
<xsd:element name="resource" type="xsd:string" />
</xsd:choice>
</xsd:complexType>

<xsd:complexType name="package">
<xsd:sequence>
<xsd:element name="base-url" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
Expand All @@ -117,7 +124,7 @@
<xsd:attribute name="cache" type="xsd:string" />
<xsd:attribute name="enable-annotations" type="xsd:boolean" />
</xsd:complexType>

<xsd:complexType name="annotations">
<xsd:attribute name="cache" type="xsd:string" />
<xsd:attribute name="debug" type="xsd:string" />
Expand Down
Expand Up @@ -96,6 +96,7 @@
<service id="templating.helper.form" class="%templating.helper.form.class%">
<tag name="templating.helper" alias="form" />
<argument type="service" id="templating.engine.php" />
<argument>%templating.helper.form.resources%</argument>
</service>

<service id="templating.globals" class="%templating.globals.class%">
Expand Down
Expand Up @@ -43,16 +43,14 @@ class FormHelper extends Helper
* @param EngineInterface $engine The templating engine
* @param array $resources An array of theme name
*/
public function __construct(EngineInterface $engine, array $resources = array())
public function __construct(EngineInterface $engine, array $resources)
{
$this->engine = $engine;
$this->resources = $resources;
$this->varStack = array();
$this->context = array();
$this->templates = array();
$this->themes = array();

$this->resources = 0 == count($resources) ? array('FrameworkBundle:Form') : $resources;

}

public function isChoiceGroup($label)
Expand Down
Expand Up @@ -46,6 +46,9 @@
'base_urls' => array('http://bar1.example.com', 'http://bar2.example.com'),
),
),
'form' => array(
'resources' => array('theme1', 'theme2')
),
),
'translator' => array(
'enabled' => true,
Expand Down
Expand Up @@ -28,6 +28,10 @@
<framework:base-url>http://bar1.example.com</framework:base-url>
<framework:base-url>http://bar2.example.com</framework:base-url>
</framework:package>
<framework:form>
<framework:resource>theme1</framework:resource>
<framework:resource>theme2</framework:resource>
</framework:form>
</framework:templating>
<framework:translator enabled="true" fallback="fr" />
<framework:validation enabled="true" cache="apc" />
Expand Down
Expand Up @@ -35,6 +35,8 @@ framework:
version: 1.0.0
bar:
base_urls: ["http://images1.example.com", "http://images2.example.com"]
form:
resources: [theme1, theme2]
translator:
enabled: true
fallback: fr
Expand Down
Expand Up @@ -121,6 +121,8 @@ public function testTemplating()
$this->assertEquals('/path/to/cache', $container->getParameter('templating.loader.cache.path'));

$this->assertEquals(array('php', 'twig'), $container->getParameter('templating.engines'), '->registerTemplatingConfiguration() sets a templating.engines parameter');

$this->assertEquals(array('FrameworkBundle:Form', 'theme1', 'theme2'), $container->getParameter('templating.helper.form.resources'), '->registerTemplatingConfiguration() registers the theme and adds the base theme');
}

public function testTranslator()
Expand Down
Expand Up @@ -38,7 +38,7 @@ protected function setUp()
$loader = new FilesystemLoader(array());
$engine = new PhpEngine($templateNameParser, $loader);

$this->helper = new FormHelper($engine);
$this->helper = new FormHelper($engine, array('FrameworkBundle:Form'));

$engine->setHelpers(array(
$this->helper,
Expand Down

0 comments on commit 5d46e63

Please sign in to comment.