aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/includes/template/twig/extension.php37
-rw-r--r--phpBB/includes/template/twig/twig.php1
2 files changed, 36 insertions, 2 deletions
diff --git a/phpBB/includes/template/twig/extension.php b/phpBB/includes/template/twig/extension.php
index 1ea5f7b662..a54c2b2509 100644
--- a/phpBB/includes/template/twig/extension.php
+++ b/phpBB/includes/template/twig/extension.php
@@ -17,11 +17,15 @@ if (!defined('IN_PHPBB'))
class phpbb_template_twig_extension extends Twig_Extension
{
+ /** @var phpbb_template_context */
+ protected $context;
+
/** @var phpbb_user */
protected $user;
- public function __construct($user)
+ public function __construct(phpbb_template_context $context, $user)
{
+ $this->context = $context;
$this->user = $user;
}
@@ -69,7 +73,7 @@ class phpbb_template_twig_extension extends Twig_Extension
public function getFunctions()
{
return array(
- new Twig_SimpleFunction('lang', array($this->user, 'lang')),
+ new Twig_SimpleFunction('lang', array($this, 'lang')),
);
}
@@ -140,4 +144,33 @@ class phpbb_template_twig_extension extends Twig_Extension
return twig_slice($env, $item, $start, $end, $preserveKeys);
}
+
+ /**
+ * Get output for a language variable (L_FOO, LA_FOO)
+ *
+ * This function checks to see if the language var was outputted to $context
+ * (e.g. in the ACP, L_TITLE)
+ * If not, we return the result of $user->lang()
+ *
+ * @param string $lang name
+ * @return string
+ */
+ function lang()
+ {
+ $args = func_get_args();
+ $key = $args[0];
+
+ $context = $this->context->get_data_ref();
+ $context_vars = $context['.'][0];
+
+ if (isset($context_vars['L_' . $key]))
+ {
+ return $context_vars['L_' . $key];
+ }
+
+ // LA_ is transformed into lang(\'$1\')|addslashes, so we should not
+ // need to check for it
+
+ return call_user_func_array(array($this->user, 'lang'), $args);
+ }
}
diff --git a/phpBB/includes/template/twig/twig.php b/phpBB/includes/template/twig/twig.php
index 9d69136e0c..347db0b94c 100644
--- a/phpBB/includes/template/twig/twig.php
+++ b/phpBB/includes/template/twig/twig.php
@@ -134,6 +134,7 @@ class phpbb_template_twig implements phpbb_template
$this->twig->addExtension(
new phpbb_template_twig_extension(
+ $this->context,
$this->user
)
);