Added support for Twig 2.11 (1.40 compatible)

This commit is contained in:
Matias Griese
2019-06-02 15:21:24 +03:00
parent 49124410b6
commit d2630409ef
3 changed files with 20 additions and 19 deletions

View File

@@ -4,6 +4,7 @@
1. [](#new)
* Require Grav v1.7
* Use PSR-4 for plugin classes
* Added support for Twig 2.11
# v1.9.5
## mm/dd/2019

View File

@@ -28,6 +28,7 @@ use PicoFeed\Parser\MalformedXmlException;
use RocketTheme\Toolbox\Event\Event;
use RocketTheme\Toolbox\File\File;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
use Twig\Loader\FilesystemLoader;
/**
@@ -2019,7 +2020,7 @@ class AdminController extends AdminBaseController
// Add theme template paths to Twig loader
$template_paths = $this->grav['locator']->findResources('theme://templates');
$this->grav['twig']->twig->getLoader()->addLoader(new \Twig_Loader_Filesystem($template_paths));
$this->grav['twig']->twig->getLoader()->addLoader(new FilesystemLoader($template_paths));
$html = $page->content();

View File

@@ -6,17 +6,16 @@ use Grav\Common\Grav;
use Grav\Common\Page\Interfaces\PageInterface;
use Grav\Common\Yaml;
use Grav\Common\Language\Language;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
class AdminTwigExtension extends \Twig_Extension
class AdminTwigExtension extends AbstractExtension
{
/**
* @var Grav
*/
/** @var Grav */
protected $grav;
/**
* @var Language $lang
*/
/** @var Language $lang */
protected $lang;
public function __construct()
@@ -25,22 +24,22 @@ class AdminTwigExtension extends \Twig_Extension
$this->lang = $this->grav['user']->language;
}
public function getFilters()
public function getFilters(): array
{
return [
new \Twig_SimpleFilter('tu', [$this, 'tuFilter']),
new \Twig_SimpleFilter('toYaml', [$this, 'toYamlFilter']),
new \Twig_SimpleFilter('fromYaml', [$this, 'fromYamlFilter']),
new \Twig_SimpleFilter('adminNicetime', [$this, 'adminNicetimeFilter']),
new \Twig_SimpleFilter('nested', [$this, 'nestedFilter']),
new TwigFilter('tu', [$this, 'tuFilter']),
new TwigFilter('toYaml', [$this, 'toYamlFilter']),
new TwigFilter('fromYaml', [$this, 'fromYamlFilter']),
new TwigFilter('adminNicetime', [$this, 'adminNicetimeFilter']),
new TwigFilter('nested', [$this, 'nestedFilter']),
];
}
public function getFunctions()
public function getFunctions(): array
{
return [
new \Twig_SimpleFunction('getPageUrl', [$this, 'getPageUrl'], ['needs_context' => true]),
new \Twig_SimpleFunction('clone', [$this, 'cloneFunc']),
new TwigFunction('getPageUrl', [$this, 'getPageUrl'], ['needs_context' => true]),
new TwigFunction('clone', [$this, 'cloneFunc']),
];
}