diff --git a/CHANGELOG.md b/CHANGELOG.md index 88e1916..ffda7b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v5.1.2 +## 09/29/2021 + +1. [](#improved) + * Improved support for Twig 2/3 + # v5.1.1 ## 09/14/2021 diff --git a/blueprints.yaml b/blueprints.yaml index 6f11ae7..aab8a6f 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Form slug: form type: plugin -version: 5.1.1 +version: 5.1.2 description: Enables the forms handling icon: check-square author: diff --git a/classes/TwigExtension.php b/classes/TwigExtension.php index 4cae01b..7bc93a6 100644 --- a/classes/TwigExtension.php +++ b/classes/TwigExtension.php @@ -12,16 +12,6 @@ */ class TwigExtension extends AbstractExtension { - /** - * Return a list of all filters. - * - * @return array - */ - public function getFilters(): array - { - return []; - } - /** * Return a list of all functions. * diff --git a/form.php b/form.php index 5344802..5f8625b 100644 --- a/form.php +++ b/form.php @@ -31,7 +31,9 @@ use RocketTheme\Toolbox\File\File; use RocketTheme\Toolbox\Event\Event; use RuntimeException; +use Twig\Environment; use Twig\Extension\CoreExtension; +use Twig\Extension\EscaperExtension; use Twig\TwigFunction; use function count; use function function_exists; @@ -355,10 +357,23 @@ public function onTwigInitialized(): void new TwigFunction('forms', [$this, 'getForm']) ); - $this->grav['twig']->twig()->getExtension(CoreExtension::class)->setEscaper('yaml', function ($twig, $string, $charset) { - return Yaml::dump($string); + if (Environment::VERSION_ID > 20000) { + // Twig 2/3 + $this->grav['twig']->twig()->getExtension(EscaperExtension::class)->setEscaper( + 'yaml', + function ($twig, $string, $charset) { + return Yaml::dump($string); + } + ); + } else { + // Twig 1.x + $this->grav['twig']->twig()->getExtension(CoreExtension::class)->setEscaper( + 'yaml', + function ($twig, $string, $charset) { + return Yaml::dump($string); + } + ); } - ); }