Skip to content

Commit

Permalink
Fix twig deprecation: twig_escape_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
WebMamba committed Dec 14, 2023
1 parent 8fe391d commit d5fb5b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/LiveComponent/src/Util/LiveAttributesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\UX\LiveComponent\Util;

use Twig\Environment;
use Twig\Extension\EscaperExtension;

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

private function escapeAttribute(string $value): string
{
return twig_escape_filter($this->twig, $value, 'html_attr');
if (class_exists(EscaperExtension::class)) {
return EscaperExtension::escape($this->twig, $value, 'html_attr');
}

// since twig/twig 3.9.0: Using the internal "twig_escape_filter" function is deprecated.
return (string) twig_escape_filter($this->twig, $value, 'html_attr');
}
}
6 changes: 6 additions & 0 deletions src/StimulusBundle/src/Dto/StimulusAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Symfony\UX\StimulusBundle\Dto;

use Twig\Environment;
use Twig\Extension\EscaperExtension;

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

private function escapeAsHtmlAttr(mixed $value): string
{
if (class_exists(EscaperExtension::class)) {
return EscaperExtension::escape($this->env, $value, 'html_attr');
}

// since twig/twig 3.9.0: Using the internal "twig_escape_filter" function is deprecated.
return (string) twig_escape_filter($this->env, $value, 'html_attr');
}

Expand Down

0 comments on commit d5fb5b2

Please sign in to comment.