[ticket/17335] Add lang_raw twig function for templates

PHPBB-17335
This commit is contained in:
Marc Alexander 2024-06-14 23:10:09 +02:00
parent 173e1ceeba
commit 48cc96b489
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
3 changed files with 20 additions and 3 deletions

View file

@ -93,6 +93,7 @@ class extension extends \Twig\Extension\AbstractExtension
new \Twig\TwigFunction('lang', array($this, 'lang')),
new \Twig\TwigFunction('lang_defined', array($this, 'lang_defined')),
new \Twig\TwigFunction('lang_js', [$this, 'lang_js']),
new \Twig\TwigFunction('lang_raw', [$this, 'lang_raw']),
new \Twig\TwigFunction('get_class', 'get_class'),
);
}
@ -214,4 +215,16 @@ class extension extends \Twig\Extension\AbstractExtension
return twig_escape_filter($this->environment, call_user_func_array([$this, 'lang'], $args), 'js');
}
/**
* Get raw value associated with lang key
*
* @param string $key
*
* @return array|string Raw value associated with lang key
*/
public function lang_raw(string $key): array|string
{
return call_user_func_array(array($this->language, 'lang_raw'), [$key]);
}
}

View file

@ -365,15 +365,15 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
array(),
array(),
array(),
"VARIABLE\n1_VARIABLE\nVARIABLE\n1_VARIABLE",
"VARIABLE\n1_VARIABLE\nVARIABLE\n1_VARIABLE\nVARIABLE\n1_VARIABLE\nARY_VARIABLE",
),
array(
'lang_twig.html',
array(),
array(),
array(),
"Value'\n1 O'Clock\nValue\\u0027\n1\\u0020O\\u0027Clock",
array('VARIABLE' => "Value'", '1_VARIABLE' => "1 O'Clock"),
"Value'\n1 O'Clock\nValue\\u0027\n1\\u0020O\\u0027Clock\nValue'\n1 O'Clock\nfoo|bar",
array('VARIABLE' => "Value'", '1_VARIABLE' => "1 O'Clock", 'ARY_VARIABLE' => ['foo', 'bar']),
),
array(
'loop_nested_multilevel_ref.html',

View file

@ -3,3 +3,7 @@
{{ lang_js('VARIABLE') }}
{{ lang_js('1_VARIABLE') }}
{{ lang_raw('VARIABLE') }}
{{ lang_raw('1_VARIABLE') }}
{{ lang_raw('ARY_VARIABLE')|join('|') }}