Skip to content

Commit a69b872

Browse files
committed
bug #1330 Fix twig deprecation: twig_escape_filter (WebMamba)
This PR was merged into the 2.x branch. Discussion ---------- Fix twig deprecation: twig_escape_filter | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Issues | | License | MIT Commits ------- 647fa8c Fix twig deprecation: twig_escape_filter
2 parents 11402b9 + 647fa8c commit a69b872

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/LiveComponent/src/Util/LiveAttributesCollection.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\UX\LiveComponent\Util;
1313

1414
use Twig\Environment;
15+
use Twig\Extension\EscaperExtension;
1516

1617
/**
1718
* An array of attributes that can eventually be returned as an escaped array.
@@ -99,6 +100,11 @@ public function setBrowserEventsToDispatch(array $browserEventsToDispatch): void
99100

100101
private function escapeAttribute(string $value): string
101102
{
102-
return twig_escape_filter($this->twig, $value, 'html_attr');
103+
if (method_exists(EscaperExtension::class, 'escape')) {
104+
return EscaperExtension::escape($this->twig, $value, 'html_attr');
105+
}
106+
107+
// since twig/twig 3.9.0: Using the internal "twig_escape_filter" function is deprecated.
108+
return (string) twig_escape_filter($this->twig, $value, 'html_attr');
103109
}
104110
}

src/StimulusBundle/src/Dto/StimulusAttributes.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Symfony\UX\StimulusBundle\Dto;
1515

1616
use Twig\Environment;
17+
use Twig\Extension\EscaperExtension;
1718

1819
/**
1920
* Helper to build Stimulus-related HTML attributes.
@@ -214,6 +215,11 @@ private function getFormattedValue(mixed $value): string
214215

215216
private function escapeAsHtmlAttr(mixed $value): string
216217
{
218+
if (method_exists(EscaperExtension::class, 'escape')) {
219+
return EscaperExtension::escape($this->env, $value, 'html_attr');
220+
}
221+
222+
// since twig/twig 3.9.0: Using the internal "twig_escape_filter" function is deprecated.
217223
return (string) twig_escape_filter($this->env, $value, 'html_attr');
218224
}
219225

0 commit comments

Comments
 (0)