Skip to content

Commit

Permalink
Merge branch 'release/5.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Sep 29, 2021
2 parents 5e806d1 + ec14e17 commit ecda5a9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v5.1.2
## 09/29/2021

1. [](#improved)
* Improved support for Twig 2/3

# v5.1.1
## 09/14/2021

Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
10 changes: 0 additions & 10 deletions classes/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
21 changes: 18 additions & 3 deletions form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
);
}
);

}

Expand Down

0 comments on commit ecda5a9

Please sign in to comment.