minor #11016 [Bridge][Twig] Replace deprecated features (egeloen)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11016).

Discussion
----------

[Bridge][Twig] Replace deprecated features

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This PR replaces the deprecated classes `Twig_Function_Node` and `Twig_Function_Method` by the`Twig_SimpleFunction`.

Commits
-------

14a4e4d [Bridge][Twig] Replace deprecated features
This commit is contained in:
Fabien Potencier 2014-06-06 05:23:41 +02:00
commit d8397b0f80
2 changed files with 36 additions and 12 deletions

View File

@ -19,7 +19,7 @@
"php": ">=5.3.3",
"symfony/icu": "~1.0",
"doctrine/common": "~2.2",
"twig/twig": "~1.11",
"twig/twig": "~1.12",
"psr/log": "~1.0"
},
"replace": {

View File

@ -61,16 +61,16 @@ class FormExtension extends \Twig_Extension
public function getFunctions()
{
return array(
'form_enctype' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\FormEnctypeNode', array('is_safe' => array('html'))),
'form_widget' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'form_errors' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'form_label' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'form_row' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'form_rest' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'form' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\RenderBlockNode', array('is_safe' => array('html'))),
'form_start' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\RenderBlockNode', array('is_safe' => array('html'))),
'form_end' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\RenderBlockNode', array('is_safe' => array('html'))),
'csrf_token' => new \Twig_Function_Method($this, 'renderer->renderCsrfToken'),
new \Twig_SimpleFunction('form_enctype', null, array('node_class' => 'Symfony\Bridge\Twig\Node\FormEnctypeNode', 'is_safe' => array('html'))),
new \Twig_SimpleFunction('form_widget', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
new \Twig_SimpleFunction('form_errors', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
new \Twig_SimpleFunction('form_label', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
new \Twig_SimpleFunction('form_row', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
new \Twig_SimpleFunction('form_rest', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
new \Twig_SimpleFunction('form', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
new \Twig_SimpleFunction('form_start', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
new \Twig_SimpleFunction('form_end', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
new \Twig_SimpleFunction('csrf_token', array($this, 'renderCsrfToken')),
);
}
@ -80,7 +80,7 @@ class FormExtension extends \Twig_Extension
public function getFilters()
{
return array(
new \Twig_SimpleFilter('humanize', array($this->renderer, 'humanize')),
new \Twig_SimpleFilter('humanize', array($this, 'humanize')),
);
}
@ -94,6 +94,30 @@ class FormExtension extends \Twig_Extension
);
}
/**
* Renders a CSRF token.
*
* @param string $intention The intention of the protected action.
*
* @return string A CSRF token.
*/
public function renderCsrfToken($intention)
{
return $this->renderer->renderCsrfToken($intention);
}
/**
* Makes a technical name human readable.
*
* @param string $text The text to humanize.
*
* @return string The humanized text.
*/
public function humanize($text)
{
return $this->renderer->humanize($text);
}
/**
* Returns whether a choice is selected for a given form value.
*