|
11 | 11 |
|
12 | 12 | namespace Symfony\UX\Vue\Twig; |
13 | 13 |
|
| 14 | +use Symfony\UX\StimulusBundle\Helper\StimulusHelper; |
14 | 15 | use Symfony\WebpackEncoreBundle\Twig\StimulusTwigExtension; |
15 | | -use Twig\Environment; |
16 | 16 | use Twig\Extension\AbstractExtension; |
17 | 17 | use Twig\TwigFunction; |
18 | 18 |
|
|
24 | 24 | */ |
25 | 25 | class VueComponentExtension extends AbstractExtension |
26 | 26 | { |
27 | | - private $stimulusExtension; |
| 27 | + private $stimulusHelper; |
28 | 28 |
|
29 | | - public function __construct(StimulusTwigExtension $stimulusExtension) |
| 29 | + /** |
| 30 | + * @param $stimulus StimulusHelper |
| 31 | + */ |
| 32 | + public function __construct(StimulusHelper|StimulusTwigExtension $stimulus) |
30 | 33 | { |
31 | | - $this->stimulusExtension = $stimulusExtension; |
| 34 | + if ($stimulus instanceof StimulusTwigExtension) { |
| 35 | + trigger_deprecation('symfony/ux-vue', '2.9', 'Passing an instance of "%s" to "%s" is deprecated, pass an instance of "%s" instead.', StimulusTwigExtension::class, __CLASS__, StimulusHelper::class); |
| 36 | + $stimulus = new StimulusHelper(null); |
| 37 | + } |
| 38 | + |
| 39 | + $this->stimulusHelper = $stimulus; |
32 | 40 | } |
33 | 41 |
|
34 | 42 | public function getFunctions(): array |
35 | 43 | { |
36 | 44 | return [ |
37 | | - new TwigFunction('vue_component', [$this, 'renderVueComponent'], ['needs_environment' => true, 'is_safe' => ['html_attr']]), |
| 45 | + new TwigFunction('vue_component', [$this, 'renderVueComponent'], ['is_safe' => ['html_attr']]), |
38 | 46 | ]; |
39 | 47 | } |
40 | 48 |
|
41 | | - public function renderVueComponent(Environment $env, string $componentName, array $props = []): string |
| 49 | + public function renderVueComponent(string $componentName, array $props = []): string |
42 | 50 | { |
43 | 51 | $params = ['component' => $componentName]; |
44 | 52 | if ($props) { |
45 | 53 | $params['props'] = $props; |
46 | 54 | } |
47 | 55 |
|
48 | | - return $this->stimulusExtension->renderStimulusController($env, '@symfony/ux-vue/vue', $params); |
| 56 | + $stimulusAttributes = $this->stimulusHelper->createStimulusAttributes(); |
| 57 | + $stimulusAttributes->addController('@symfony/ux-vue/vue', $params); |
| 58 | + |
| 59 | + return (string) $stimulusAttributes; |
49 | 60 | } |
50 | 61 | } |
0 commit comments