14
14
use Symfony \Bundle \TwigBundle \TokenParser \RenderTokenParser ;
15
15
use Symfony \Bundle \FrameworkBundle \Templating \Helper \ActionsHelper ;
16
16
use Symfony \Component \DependencyInjection \ContainerInterface ;
17
+ use Symfony \Component \HttpKernel \Fragment \FragmentHandler ;
17
18
18
19
/**
19
20
* Twig extension for Symfony actions helper.
24
25
*/
25
26
class ActionsExtension extends \Twig_Extension
26
27
{
27
- private $ container ;
28
+ private $ handler ;
28
29
29
30
/**
30
- * Constructor.
31
+ * @param FragmentHandler|ContainerInterface $handler
31
32
*
32
- * @param ContainerInterface $container The service container
33
+ * @deprecated Passing a ContainerInterface as a first argument is deprecated as of 2.7 and will be removed in 3.0.
33
34
*/
34
- public function __construct (ContainerInterface $ container )
35
+ public function __construct ($ handler )
35
36
{
36
- $ this ->container = $ container ;
37
+ if ($ handler instanceof FragmentHandler) {
38
+ $ this ->handler = $ handler ;
39
+ } elseif ($ handler instanceof ContainerInterface) {
40
+ trigger_error (sprintf ('The ability to pass a ContainerInterface instance as a first argument to %s was deprecated in 2.7 and will be removed in 3.0. Please, pass a FragmentHandler instance instead. ' , __METHOD__ ), E_USER_DEPRECATED );
41
+
42
+ $ this ->handler = $ handler ->get ('fragment.handler ' );
43
+ } else {
44
+ throw new \BadFunctionCallException (sprintf ('%s takes a FragmentHandler or a ContainerInterface object as its first argument. ' , __METHOD__ ));
45
+ }
46
+
47
+ $ this ->handler = $ handler ;
37
48
}
38
49
39
50
/**
@@ -42,11 +53,14 @@ public function __construct(ContainerInterface $container)
42
53
* @param string $uri A URI
43
54
* @param array $options An array of options
44
55
*
45
- * @see ActionsHelper ::render()
56
+ * @see FragmentHandler ::render()
46
57
*/
47
58
public function renderUri ($ uri , array $ options = array ())
48
59
{
49
- return $ this ->container ->get ('templating.helper.actions ' )->render ($ uri , $ options );
60
+ $ strategy = isset ($ options ['strategy ' ]) ? $ options ['strategy ' ] : 'inline ' ;
61
+ unset($ options ['strategy ' ]);
62
+
63
+ return $ this ->handler ->render ($ uri , $ strategy , $ options );
50
64
}
51
65
52
66
/**
0 commit comments