mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-07 09:24:14 +02:00
[ticket/15538] Readding macros and requested changes
PHPBB3-15538
This commit is contained in:
parent
23fae74bf2
commit
341266cc71
phpBB
phpbb/template/twig/extension
styles/all/template
@ -23,7 +23,7 @@ class icon extends \Twig\Extension\AbstractExtension
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\user $user User object
|
||||
* @param \phpbb\user $user User object
|
||||
*/
|
||||
public function __construct(\phpbb\user $user)
|
||||
{
|
||||
@ -33,7 +33,7 @@ class icon extends \Twig\Extension\AbstractExtension
|
||||
/**
|
||||
* Returns the name of this extension.
|
||||
*
|
||||
* @return string The extension name
|
||||
* @return string The extension name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
@ -43,7 +43,7 @@ class icon extends \Twig\Extension\AbstractExtension
|
||||
/**
|
||||
* Returns a list of filters to add to the existing list.
|
||||
*
|
||||
* @return \Twig\TwigFilter[]
|
||||
* @return \Twig\TwigFilter[] Array of twig filters
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
@ -55,7 +55,7 @@ class icon extends \Twig\Extension\AbstractExtension
|
||||
/**
|
||||
* Returns a list of functions to add to the existing list.
|
||||
*
|
||||
* @return \Twig\TwigFunction[]
|
||||
* @return \Twig\TwigFunction[] Array of twig functions
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
@ -77,7 +77,7 @@ class icon extends \Twig\Extension\AbstractExtension
|
||||
$web_path = $board_url ? generate_board_url() . '/' : $environment->get_web_root_path();
|
||||
$style_path = $this->user->style['style_path'];
|
||||
|
||||
return "{$web_path}styles/{$style_path}/template/icons/png/{$icon}.png";
|
||||
return "{$web_path}styles/{$style_path}/theme/icons/png/{$icon}.png";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,7 +18,7 @@ class implode extends \Twig\Extension\AbstractExtension
|
||||
/**
|
||||
* Returns the name of this extension.
|
||||
*
|
||||
* @return string The extension name
|
||||
* @return string The extension name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
@ -28,7 +28,7 @@ class implode extends \Twig\Extension\AbstractExtension
|
||||
/**
|
||||
* Returns a list of functions to add to the existing list.
|
||||
*
|
||||
* @return \Twig\TwigFunction[]
|
||||
* @return \Twig\TwigFunction[] Array of twig functions
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
@ -47,8 +47,8 @@ class implode extends \Twig\Extension\AbstractExtension
|
||||
* Implode_attributes('checked', {'data-ajax': 'true'})
|
||||
* Implode_attributes(['checked', {'data-ajax': 'true'}])
|
||||
*
|
||||
* @param mixed $arguments
|
||||
* @return string
|
||||
* @param mixed $arguments Attributes to implode
|
||||
* @return string The attributes string
|
||||
*/
|
||||
public function implode_attributes(...$arguments)
|
||||
{
|
||||
@ -132,8 +132,8 @@ class implode extends \Twig\Extension\AbstractExtension
|
||||
* 'hidden-class': S_POST_HIDDEN,
|
||||
* }])
|
||||
*
|
||||
* @param mixed $arguments
|
||||
* @return string The classes string prepended with a space
|
||||
* @param mixed $arguments The classes to implode
|
||||
* @return string The classes string prepended with a space
|
||||
*/
|
||||
public function implode_classes(...$arguments)
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ class macro extends \Twig\Extension\AbstractExtension implements \Twig\Extension
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param environment $twig Twig environment object
|
||||
* @param environment $twig Twig environment object
|
||||
*/
|
||||
public function __construct(environment $twig)
|
||||
{
|
||||
@ -33,7 +33,7 @@ class macro extends \Twig\Extension\AbstractExtension implements \Twig\Extension
|
||||
/**
|
||||
* Returns the name of this extension.
|
||||
*
|
||||
* @return string The extension name
|
||||
* @return string The extension name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
@ -43,22 +43,13 @@ class macro extends \Twig\Extension\AbstractExtension implements \Twig\Extension
|
||||
/**
|
||||
* Returns a list of global variables to add to the existing list.
|
||||
*
|
||||
* @return array An array of global variables
|
||||
* @throws \Twig\Error\Error
|
||||
* @return array An array of global variables
|
||||
*/
|
||||
public function getGlobals()
|
||||
{
|
||||
$macros = null;
|
||||
|
||||
try
|
||||
{
|
||||
$macros = $this->twig->loadTemplate('macros.html');
|
||||
}
|
||||
catch (\Twig\Error\Error $e)
|
||||
{
|
||||
}
|
||||
|
||||
return [
|
||||
'macros' => $macros,
|
||||
'macros' => $this->twig->loadTemplate('macros/macros.twig'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
{# Wrapper function #}
|
||||
{% macro Icon(type, icon, classes = '', title = '', hidden = false, attributes = {}) %}
|
||||
{% set type = type|capitalize %}
|
||||
Hello
|
||||
{% endmacro Icon %}
|
34
phpBB/styles/all/template/macros/macros.twig
Normal file
34
phpBB/styles/all/template/macros/macros.twig
Normal file
@ -0,0 +1,34 @@
|
||||
{# Wrapper function #}
|
||||
{% macro Icon(type, icon, classes = '', title = '', hidden = false, attributes = {}) %}
|
||||
{% set type = type|capitalize %}
|
||||
|
||||
{% if type in ['Fa', 'Png', 'Svg'] %}
|
||||
{{ attribute(_self, type, [icon, classes, title, hidden, attributes]) }}
|
||||
{% endif %}
|
||||
{% endmacro Icon %}
|
||||
|
||||
{# FA icons #}
|
||||
{% macro Fa(icon, classes = '', title = '', hidden = false, attributes = {}) %}
|
||||
<i class="o-icon font fa-{{ icon ~ Implode_classes(classes) }}"{% if hidden %}{% if title %} title="{{ lang(title) }}"{% endif %} aria-hidden="true"{% endif %}{{ Implode_attributes(attributes) }}></i>
|
||||
{% if title %}<span{% if hidden %} class="sr-only"{% endif %}>{{ lang(title) }}</span>{% endif %}
|
||||
{% endmacro Fa %}
|
||||
|
||||
{# PNG icons #}
|
||||
{% macro Png(icon, classes = '', title = '', hidden = false, attributes = {}) %}
|
||||
<img class="o-icon png png-{{ icon ~ Implode_classes(classes) }}" src="{{ icon|png_path }}" alt="{{ lang(title) }}"{{ _self.attributes(attributes) }}
|
||||
{% endmacro Png %}
|
||||
|
||||
{# SVG icons #}
|
||||
{% macro Svg(icon, classes = '', title = '', hidden = false, attributes = {}) %}
|
||||
{% set title_id = title ? title|lower|replace({' ': '_'}) ~ '-' ~ random() %}
|
||||
|
||||
<svg class="o-icon svg svg-{{ icon ~ Implode_classes(classes) }}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"{% if title %}{% if hidden %} aria-hidden="true"{% endif %} aria-labelledby="{{ title_id }}"{% endif %} role="img"{{ Implode_attributes(attributes) }}>
|
||||
{% if title %}
|
||||
<title id="{{ title_id }}">{{ lang(title) }}</title>
|
||||
{% endif %}
|
||||
|
||||
{{ Svg_clean(icon) }}
|
||||
</svg>
|
||||
{% endmacro Svg %}
|
||||
|
||||
{% from _self import Icon as Icon %}
|
Loading…
x
Reference in New Issue
Block a user