Skip to content

Commit 42b4665

Browse files
committed
bug #914 [TwigComponent] Fix breaking (deprecation instead) when using .add() + StimulusBundle (weaverryan)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [TwigComponent] Fix breaking (deprecation instead) when using .add() + StimulusBundle | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Tickets | None - reported on Slack. | License | MIT Accidental break if upgrading to use new StimulusBundle, but still using `attributes.add(stimulus_controller())`. Cheers! Commits ------- 88f1f05 [TwigComponent] Fix breaking (deprecation instead) when using .add() + StimulusBundle
2 parents 1043fb1 + 88f1f05 commit 42b4665

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/TwigComponent/src/ComponentAttributes.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\UX\TwigComponent;
1313

14+
use Symfony\UX\StimulusBundle\Dto\StimulusAttributes;
1415
use Symfony\WebpackEncoreBundle\Dto\AbstractStimulusDto;
1516

1617
/**
@@ -115,9 +116,17 @@ public function without(string ...$keys): self
115116
return $clone;
116117
}
117118

118-
public function add(AbstractStimulusDto $stimulusDto): self
119+
public function add($stimulusDto): self
119120
{
120-
trigger_deprecation('symfony/ux-twig-component', '2.9.0', 'Passing a StimulusDto to ComponentAttributes::add() is deprecated. Run "composer require symfony/stimulus-bundle" then use "attributes.defaults(stimulus_controller(\'...\'))".');
121+
if ($stimulusDto instanceof AbstractStimulusDto) {
122+
trigger_deprecation('symfony/ux-twig-component', '2.9.0', 'Passing a StimulusDto to ComponentAttributes::add() is deprecated. Run "composer require symfony/stimulus-bundle" then use "attributes.defaults(stimulus_controller(\'...\'))".');
123+
} elseif ($stimulusDto instanceof StimulusAttributes) {
124+
trigger_deprecation('symfony/ux-twig-component', '2.9.0', 'Calling ComponentAttributes::add() is deprecated. Instead use "attributes.defaults(stimulus_controller(\'...\'))".');
125+
126+
return $this->defaults($stimulusDto);
127+
} else {
128+
throw new \InvalidArgumentException(sprintf('Argument 1 passed to "%s()" must be an instance of "%s" or "%s", "%s" given.', __METHOD__, AbstractStimulusDto::class, StimulusAttributes::class, get_debug_type($stimulusDto)));
129+
}
121130

122131
$controllersAttributes = $stimulusDto->toArray();
123132
$attributes = $this->attributes;

0 commit comments

Comments
 (0)