From f9d9f6cd27076a9a17d3cf009cb494bc0802f6a5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaime=20Pe=CC=81rez=20Crespo?= <jaime.perez@uninett.no>
Date: Wed, 6 Dec 2017 14:44:18 +0100
Subject: [PATCH] Add support for our custom module path formats in the new
 Twig template loader.

Now we can load templates in twig with two syntaxes:

- The original twig syntax: "@module/path/to/template.twig"
- The SSP syntax: "module:path/to/template.php" or "module:path/to/template.tpl.php"
---
 lib/SimpleSAML/XHTML/TemplateLoader.php | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/lib/SimpleSAML/XHTML/TemplateLoader.php b/lib/SimpleSAML/XHTML/TemplateLoader.php
index e24dd2700..d3a9f853c 100644
--- a/lib/SimpleSAML/XHTML/TemplateLoader.php
+++ b/lib/SimpleSAML/XHTML/TemplateLoader.php
@@ -25,6 +25,22 @@ class TemplateLoader extends \Twig\Loader\FilesystemLoader
         return parent::findTemplate($name);
     }
 
+
+    protected function parseName($name, $default = self::MAIN_NAMESPACE)
+    {
+        if (strpos($name, ':')) {
+            // we have our old SSP format
+            list($namespace, $shortname) = explode(':', $name, 2);
+            $shortname = strtr($shortname, array(
+                '.tpl.php' => '.twig',
+                '.php' => '.twig',
+            ));
+            return array($namespace, $shortname);
+        }
+        return parent::parseName($name, $default);
+    }
+
+
     /**
      * Get the template directory of a module, if it exists.
      *
-- 
GitLab