mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-11 05:48:51 +00:00
[ticket/16856] Add lang_js() twig function
PHPBB3-16856
This commit is contained in:
parent
75df7c202e
commit
5eeb213b12
1 changed files with 16 additions and 0 deletions
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
namespace phpbb\template\twig;
|
namespace phpbb\template\twig;
|
||||||
|
|
||||||
|
use Twig\Error\RuntimeError;
|
||||||
|
|
||||||
class extension extends \Twig\Extension\AbstractExtension
|
class extension extends \Twig\Extension\AbstractExtension
|
||||||
{
|
{
|
||||||
/** @var \phpbb\template\context */
|
/** @var \phpbb\template\context */
|
||||||
|
@ -90,6 +92,7 @@ class extension extends \Twig\Extension\AbstractExtension
|
||||||
return array(
|
return array(
|
||||||
new \Twig\TwigFunction('lang', array($this, 'lang')),
|
new \Twig\TwigFunction('lang', array($this, 'lang')),
|
||||||
new \Twig\TwigFunction('lang_defined', array($this, 'lang_defined')),
|
new \Twig\TwigFunction('lang_defined', array($this, 'lang_defined')),
|
||||||
|
new \Twig\TwigFunction('lang_js', [$this, 'lang_js']),
|
||||||
new \Twig\TwigFunction('get_class', 'get_class'),
|
new \Twig\TwigFunction('get_class', 'get_class'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -198,4 +201,17 @@ class extension extends \Twig\Extension\AbstractExtension
|
||||||
{
|
{
|
||||||
return call_user_func_array([$this->language, 'is_set'], [$key]);
|
return call_user_func_array([$this->language, 'is_set'], [$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get output for language variable in JS code
|
||||||
|
*
|
||||||
|
* @throws RuntimeError When data passed to twig_escape_filter is not a UTF8 string
|
||||||
|
*/
|
||||||
|
public function lang_js(): string
|
||||||
|
{
|
||||||
|
$args = func_get_args();
|
||||||
|
|
||||||
|
return twig_escape_filter($this->environment, call_user_func_array([$this, 'lang'], $args), 'js');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue