Skip to content

Commit

Permalink
extended twig renderer to expose javascript and style render methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bamarni committed Jul 19, 2012
1 parent 346d662 commit 0cfdb07
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
33 changes: 33 additions & 0 deletions Form/GenemuRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the Genemu package.
*
* (c) Olivier Chauvel <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Genemu\Bundle\FormBundle\Form;

use Symfony\Bridge\Twig\Form\TwigRenderer;
use Symfony\Component\Form\FormViewInterface;

/**
* Adds javascript and stylesheet sections support.
*
* @author Bilal Amarni <[email protected]>
*/
class GenemuRenderer extends TwigRenderer
{
public function renderJavascript(FormViewInterface $view)
{
return $this->renderSection($view, 'javascript');
}

public function renderStylesheet(FormViewInterface $view)
{
return $this->renderSection($view, 'stylesheet');
}
}
6 changes: 5 additions & 1 deletion Resources/config/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
<services>
<service id="genemu.twig.extension.form" class="Genemu\Bundle\FormBundle\Twig\Extension\FormExtension">
<tag name="twig.extension" />
<argument type="service" id="twig.form.renderer" />
<argument type="service" id="genemu.form.renderer" />
</service>
<service id="genemu.form.renderer" class="Genemu\Bundle\FormBundle\Form\GenemuRenderer" public="false">
<argument type="service" id="twig.form.engine" />
<argument type="service" id="form.csrf_provider" on-invalid="null" />
</service>
</services>

Expand Down
29 changes: 2 additions & 27 deletions Twig/Extension/FormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Genemu\Bundle\FormBundle\Twig\Extension;

use Symfony\Bridge\Twig\Extension\FormExtension as BaseFormExtension;
use Symfony\Component\Form\FormView;

/**
* FormExtension extends Twig with form capabilities.
Expand All @@ -27,35 +26,11 @@ class FormExtension extends BaseFormExtension
public function getFunctions()
{
return array(
'form_javascript' => new \Twig_Function_Method($this, 'renderJavascript', array('is_safe' => array('html'))),
'form_stylesheet' => new \Twig_Function_Method($this, 'renderStylesheet', array('is_safe' => array('html'))),
'form_javascript' => new \Twig_Function_Method($this, 'renderer->renderJavascript', array('is_safe' => array('html'))),
'form_stylesheet' => new \Twig_Function_Method($this, 'renderer->renderStylesheet', array('is_safe' => array('html'))),
);
}

/**
* Render Function Form Javascript
*
* @param FromView $view
*
* @return string
*/
public function renderJavascript(FormView $view)
{
return $this->render($view, 'javascript');
}

/**
* Render Function Form Stylesheet
*
* @param FromView $view
*
* @return string
*/
public function renderStylesheet(FormView $view)
{
return $this->render($view, 'stylesheet');
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit 0cfdb07

Please sign in to comment.