Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3ce8ad1

Browse filesBrowse files
committed
fixed HelpersExtension (removed usage of the magic _view context attribute -- helpers should now work from macros)
1 parent eff1bdf commit 3ce8ad1
Copy full SHA for 3ce8ad1

File tree

Expand file treeCollapse file tree

3 files changed

+27
-9
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+27
-9
lines changed

‎src/Symfony/Bundle/TwigBundle/Extension/HelpersExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Extension/HelpersExtension.php
+21-8Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Symfony\Bundle\TwigBundle\Extension;
44

55
use Symfony\Bundle\TwigBundle\TokenParser\HelperTokenParser;
6+
use Symfony\Component\DependencyInjection\ContainerInterface;
67

78
/*
89
* This file is part of the Symfony package.
@@ -19,6 +20,18 @@
1920
*/
2021
class HelpersExtension extends \Twig_Extension
2122
{
23+
protected $container;
24+
25+
public function __construct(ContainerInterface $container)
26+
{
27+
$this->container = $container;
28+
}
29+
30+
public function getContainer()
31+
{
32+
return $this->container;
33+
}
34+
2235
/**
2336
* Returns the token parser instance to add to the existing list.
2437
*
@@ -28,28 +41,28 @@ public function getTokenParsers()
2841
{
2942
return array(
3043
// {% javascript 'bundles/blog/js/blog.js' %}
31-
new HelperTokenParser('javascript', '<js> [with <arguments:array>]', 'javascripts', 'add'),
44+
new HelperTokenParser('javascript', '<js> [with <arguments:array>]', 'templating.helper.javascripts', 'add'),
3245

3346
// {% javascripts %}
34-
new HelperTokenParser('javascripts', '', 'javascripts', 'render'),
47+
new HelperTokenParser('javascripts', '', 'templating.helper.javascripts', 'render'),
3548

3649
// {% stylesheet 'bundles/blog/css/blog.css' with ['media': 'screen'] %}
37-
new HelperTokenParser('stylesheet', '<css> [with <arguments:array>]', 'stylesheets', 'add'),
50+
new HelperTokenParser('stylesheet', '<css> [with <arguments:array>]', 'templating.helper.stylesheets', 'add'),
3851

3952
// {% stylesheets %}
40-
new HelperTokenParser('stylesheets', '', 'stylesheets', 'render'),
53+
new HelperTokenParser('stylesheets', '', 'templating.helper.stylesheets', 'render'),
4154

4255
// {% asset 'css/blog.css' %}
43-
new HelperTokenParser('asset', '<location>', 'assets', 'getUrl'),
56+
new HelperTokenParser('asset', '<location>', 'templating.helper.assets', 'getUrl'),
4457

4558
// {% route 'blog_post' with ['id': post.id] %}
46-
new HelperTokenParser('route', '<route> [with <arguments:array>]', 'router', 'generate'),
59+
new HelperTokenParser('route', '<route> [with <arguments:array>]', 'templating.helper.router', 'generate'),
4760

4861
// {% render 'BlogBundle:Post:list' with ['limit': 2], ['alt': 'BlogBundle:Post:error'] %}
49-
new HelperTokenParser('render', '<template> [with <attributes:array>[, <options:array>]]', 'actions', 'render'),
62+
new HelperTokenParser('render', '<template> [with <attributes:array>[, <options:array>]]', 'templating.helper.actions', 'render'),
5063

5164
// {% flash 'notice' %}
52-
new HelperTokenParser('flash', '<name>', 'session', 'flash'),
65+
new HelperTokenParser('flash', '<name>', 'templating.helper.session', 'flash'),
5366
);
5467
}
5568

‎src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
<service id="twig.extension.helpers" class="Symfony\Bundle\TwigBundle\Extension\HelpersExtension">
4646
<tag name="twig.extension" />
47+
<argument type="service" id="service_container" />
4748
</service>
4849
</services>
4950
</container>

‎src/Symfony/Bundle/TwigBundle/TokenParser/HelperTokenParser.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/TokenParser/HelperTokenParser.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ protected function getNode(array $values, $line)
5656
return $this->output(
5757
$this->markAsSafe(
5858
$this->call(
59-
$this->getAttribute('_view', $this->helper),
59+
$this->call(
60+
$this->call(new \Twig_Node_Expression_ExtensionReference('symfony.helpers', 0), 'getContainer'),
61+
'get',
62+
array(new \Twig_Node_Expression_Constant($this->helper, 0))
63+
),
6064
$this->method,
6165
$this->getNodeValues($values)
6266
)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.