Skip to content

Commit b8ff4a6

Browse files
committed
feature #211 [WIP] Deprecating the stimulus functionality in favor of an upcoming StimulusBundle (weaverryan)
This PR was squashed before being merged into the main branch. Discussion ---------- [WIP] Deprecating the stimulus functionality in favor of an upcoming StimulusBundle Hi! This isn't ready yet, but a new StimulusBundle is being created that will now be the home of the `stimulus_` Twig functions 🎆 . This PR is to deprecate those functions and only load them if the StimulusBundle is not present. Cheers! Commits ------- 2a15b75 [WIP] Deprecating the stimulus functionality in favor of an upcoming StimulusBundle
2 parents 101b9b2 + 2a15b75 commit b8ff4a6

File tree

11 files changed

+54
-157
lines changed

11 files changed

+54
-157
lines changed

.github/workflows/static.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
composer-options: "--working-dir=tools/php-cs-fixer"
5050

5151
- name: PHP-CS-Fixer
52-
run: tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --format=checkstyle | cs2pr
52+
run: tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run
5353

5454
psalm:
5555
name: Psalm

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v1.17.0
4+
5+
- Deprecated the `stimulus_controller()`, `stimulus_action()` and `stimulus_target`
6+
functions and related classes. Install `symfony/stimulus-bundle` instead.
7+
38
## [v1.16.0](https://github.com/symfony/webpack-encore-bundle/releases/tag/v1.16.0)
49

510
*October 18th, 2022*

doc/index.rst

Lines changed: 4 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -204,160 +204,11 @@ different ways:
204204
Stimulus / Symfony UX Helper
205205
----------------------------
206206

207-
stimulus_controller
208-
~~~~~~~~~~~~~~~~~~~
209-
210-
This bundle also ships with a special ``stimulus_controller()`` Twig function
211-
that can be used to render `Stimulus Controllers & Values`_ and `CSS Classes`_.
212-
See `stimulus-bridge`_ for more details.
213-
214-
For example:
215-
216-
.. code-block:: html+twig
217-
218-
<div {{ stimulus_controller('chart', { 'name': 'Likes', 'data': [1, 2, 3, 4] }) }}>
219-
Hello
220-
</div>
221-
222-
<!-- would render -->
223-
<div
224-
data-controller="chart"
225-
data-chart-name-value="Likes"
226-
data-chart-data-value="&#x5B;1,2,3,4&#x5D;"
227-
>
228-
Hello
229-
</div>
230-
231-
If you want to set CSS classes:
232-
233-
.. code-block:: html+twig
234-
235-
<div {{ stimulus_controller('chart', { 'name': 'Likes', 'data': [1, 2, 3, 4] }, { 'loading': 'spinner' }) }}>
236-
Hello
237-
</div>
238-
239-
<!-- would render -->
240-
<div
241-
data-controller="chart"
242-
data-chart-name-value="Likes"
243-
data-chart-data-value="&#x5B;1,2,3,4&#x5D;"
244-
data-chart-loading-class="spinner"
245-
>
246-
Hello
247-
</div>
248-
249-
<!-- or without values -->
250-
<div {{ stimulus_controller('chart', controllerClasses = { 'loading': 'spinner' }) }}>
251-
Hello
252-
</div>
253-
254-
Any non-scalar values (like ``data: [1, 2, 3, 4]``) are JSON-encoded. And all
255-
values are properly escaped (the string ``&#x5B;`` is an escaped
256-
``[`` character, so the attribute is really ``[1,2,3,4]``).
257-
258-
If you have multiple controllers on the same element, you can chain them as there's also a ``stimulus_controller`` filter:
259-
260-
.. code-block:: html+twig
261-
262-
<div {{ stimulus_controller('chart', { 'name': 'Likes' })|stimulus_controller('other-controller') }}>
263-
Hello
264-
</div>
265-
266-
You can also retrieve the generated attributes as an array, which can be helpful e.g. for forms:
267-
268-
.. code-block:: twig
269-
270-
{{ form_start(form, { attr: stimulus_controller('chart', { 'name': 'Likes' }).toArray() }) }}
271-
272-
stimulus_action
273-
~~~~~~~~~~~~~~~
274-
275-
The ``stimulus_action()`` Twig function can be used to render `Stimulus Actions`_.
276-
277-
For example:
278-
279-
.. code-block:: html+twig
280-
281-
<div {{ stimulus_action('controller', 'method') }}>Hello</div>
282-
<div {{ stimulus_action('controller', 'method', 'click') }}>Hello</div>
283-
284-
<!-- would render -->
285-
<div data-action="controller#method">Hello</div>
286-
<div data-action="click->controller#method">Hello</div>
287-
288-
If you have multiple actions and/or methods on the same element, you can chain them as there's also a
289-
``stimulus_action`` filter:
290-
291-
.. code-block:: html+twig
292-
293-
<div {{ stimulus_action('controller', 'method')|stimulus_action('other-controller', 'test') }}>
294-
Hello
295-
</div>
296-
297-
<!-- would render -->
298-
<div data-action="controller#method other-controller#test">
299-
Hello
300-
</div>
301-
302-
You can also retrieve the generated attributes as an array, which can be helpful e.g. for forms:
303-
304-
.. code-block:: twig
305-
306-
{{ form_row(form.password, { attr: stimulus_action('hello-controller', 'checkPasswordStrength').toArray() }) }}
307-
308-
You can also pass `parameters`_ to actions:
309-
310-
.. code-block:: html+twig
311-
312-
<div {{ stimulus_action('hello-controller', 'method', 'click', { 'count': 3 }) }}>Hello</div>
313-
314-
<!-- would render -->
315-
<div data-action="click->hello-controller#method" data-hello-controller-count-param="3">Hello</div>
316-
317-
stimulus_target
318-
~~~~~~~~~~~~~~~
319-
320-
The ``stimulus_target()`` Twig function can be used to render `Stimulus Targets`_.
321-
322-
For example:
323-
324-
.. code-block:: html+twig
325-
326-
<div {{ stimulus_target('controller', 'a-target') }}>Hello</div>
327-
<div {{ stimulus_target('controller', 'a-target second-target') }}>Hello</div>
328-
329-
<!-- would render -->
330-
<div data-controller-target="a-target">Hello</div>
331-
<div data-controller-target="a-target second-target">Hello</div>
332-
333-
If you have multiple targets on the same element, you can chain them as there's also a `stimulus_target` filter:
334-
335-
.. code-block:: html+twig
336-
337-
<div {{ stimulus_target('controller', 'a-target')|stimulus_target('other-controller', 'another-target') }}>
338-
Hello
339-
</div>
340-
341-
<!-- would render -->
342-
<div data-controller-target="a-target" data-other-controller-target="another-target">
343-
Hello
344-
</div>
345-
346-
You can also retrieve the generated attributes as an array, which can be helpful e.g. for forms:
347-
348-
.. code-block:: twig
349-
350-
{{ form_row(form.password, { attr: stimulus_target('hello-controller', 'a-target').toArray() }) }}
351-
352-
Ok, have fun!
353-
207+
The ``stimulus_controller()``, ``stimulus_action()`` and ``stimulus_target()``
208+
Twig functions are deprecated in WebpackEncoreBundle 1.17.0. Install and
209+
use `symfony/stimulus-bundle`_ for that functionality.
354210

355211
.. _`Webpack Encore`: https://symfony.com/doc/current/frontend.html
356212
.. _`enable the bundle manually`: https://symfony.com/doc/current/bundles.html
357213
.. _`"splits" your files`: https://webpack.js.org/plugins/split-chunks-plugin/
358-
.. _`Stimulus Controllers & Values`: https://stimulus.hotwired.dev/reference/values
359-
.. _`CSS Classes`: https://stimulus.hotwired.dev/reference/css-classes
360-
.. _`stimulus-bridge`: https://github.com/symfony/stimulus-bridge
361-
.. _`Stimulus Actions`: https://stimulus.hotwired.dev/reference/actions
362-
.. _`parameters`: https://stimulus.hotwired.dev/reference/actions#action-parameters
363-
.. _`Stimulus Targets`: https://stimulus.hotwired.dev/reference/targets
214+
.. _`symfony/stimulus-bundle`: https://symfony.com/bundles/StimulusBundle/current/index.html

src/CacheWarmer/EntrypointCacheWarmer.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ public function __construct(array $cacheKeys, string $phpArrayFile)
2424
parent::__construct($phpArrayFile);
2525
}
2626

27-
/**
28-
* {@inheritdoc}
29-
*/
3027
protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter): bool
3128
{
3229
foreach ($this->cacheKeys as $cacheKey => $path) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony WebpackEncoreBundle package.
5+
* (c) Fabien Potencier <[email protected]>
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace Symfony\WebpackEncoreBundle\DependencyInjection\Compiler;
11+
12+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13+
use Symfony\Component\DependencyInjection\ContainerBuilder;
14+
15+
class RemoveStimulusServicesPass implements CompilerPassInterface
16+
{
17+
public function process(ContainerBuilder $container)
18+
{
19+
if ($container->hasDefinition('stimulus.helper')) {
20+
// remove the Stimulus integration if StimulusBundle is installed
21+
$container->removeDefinition('webpack_encore.twig_stimulus_extension');
22+
}
23+
}
24+
}

src/Dto/AbstractStimulusDto.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
/**
1717
* @internal
18+
*
19+
* @deprecated since 1.17.0 - install symfony/stimulus-bundle instead.
1820
*/
1921
abstract class AbstractStimulusDto implements \Stringable
2022
{

src/Dto/StimulusActionsDto.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Symfony\WebpackEncoreBundle\Dto;
1313

14+
/**
15+
* @deprecated since 1.17.0 - install symfony/stimulus-bundle instead.
16+
*/
1417
final class StimulusActionsDto extends AbstractStimulusDto
1518
{
1619
private $actions = [];

src/Dto/StimulusControllersDto.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Symfony\WebpackEncoreBundle\Dto;
1313

14+
/**
15+
* @deprecated since 1.17.0 - install symfony/stimulus-bundle instead.
16+
*/
1417
final class StimulusControllersDto extends AbstractStimulusDto
1518
{
1619
private $controllers = [];

src/Dto/StimulusTargetsDto.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Symfony\WebpackEncoreBundle\Dto;
1313

14+
/**
15+
* @deprecated since 1.17.0 - install symfony/stimulus-bundle instead.
16+
*/
1417
final class StimulusTargetsDto extends AbstractStimulusDto
1518
{
1619
private $targets = [];

src/Twig/StimulusTwigExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
use Twig\TwigFilter;
1818
use Twig\TwigFunction;
1919

20+
/**
21+
* @deprecated since 1.17.0 - install symfony/stimulus-bundle instead.
22+
*/
2023
final class StimulusTwigExtension extends AbstractExtension
2124
{
2225
public function getFunctions(): array

src/WebpackEncoreBundle.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99

1010
namespace Symfony\WebpackEncoreBundle;
1111

12+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1213
use Symfony\Component\HttpKernel\Bundle\Bundle;
14+
use Symfony\WebpackEncoreBundle\DependencyInjection\Compiler\RemoveStimulusServicesPass;
1315

1416
final class WebpackEncoreBundle extends Bundle
1517
{
18+
public function build(ContainerBuilder $container)
19+
{
20+
$container->addCompilerPass(new RemoveStimulusServicesPass());
21+
}
1622
}

0 commit comments

Comments
 (0)