From d0e096907176b9b028b6cf30b06713e8c8436100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Pe=CC=81rez=20Crespo?= <jaime.perez@uninett.no> Date: Tue, 4 Jul 2017 13:18:50 +0200 Subject: [PATCH] Add a method to get the twig object used in a template. This allows template users to use their own twig extensions if they want, while also allowing us to remove the "twigInit" hook. Hooks come at a price, and it doesn't make much sense to use them in this case, as they would only be useful if a module wants to add a twig extension even if the code instantiating SimpleSAML_XHTML_Template does not belong to that module. This could lead to unexpected behaviour (i.e. a module adding a hook that creates trouble for the templates defined in another module), so given the lack of use cases supporting the hook and the possible negative consequences implied, it's better to remove it. --- lib/SimpleSAML/XHTML/Template.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php index d2f860a88..19edb5650 100644 --- a/lib/SimpleSAML/XHTML/Template.php +++ b/lib/SimpleSAML/XHTML/Template.php @@ -198,7 +198,6 @@ class SimpleSAML_XHTML_Template $twig = new Twig_Environment($loader, $options); $twig->addExtension(new Twig_Extensions_Extension_I18n()); - SimpleSAML\Module::callHooks('twigInit', $twig); return $twig; } @@ -476,6 +475,17 @@ class SimpleSAML_XHTML_Template } + /** + * Get the current instance of Twig in use. + * + * @return false|Twig_Environment The Twig instance in use, or false if Twig is not used. + */ + public function getTwig() + { + return $this->twig; + } + + /* * Deprecated methods of this interface, all of them should go away. */ -- GitLab