1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the adminbsb-material-design-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2017 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\AdminBSBBundle\Twig\Extension\UI; |
13
|
|
|
|
14
|
|
|
use Twig\TwigFunction; |
15
|
|
|
use WBW\Bundle\CoreBundle\Renderer\IconRendererInterface; |
16
|
|
|
use WBW\Library\Core\Argument\Helper\ArrayHelper; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Icon Twig extension. |
20
|
|
|
* |
21
|
|
|
* @author webeweb <https://github.com/webeweb/> |
22
|
|
|
* @package WBW\Bundle\AdminBSBBundle\Twig\Extension\UI |
23
|
|
|
*/ |
24
|
|
|
class IconTwigExtension extends AbstractIconTwigExtension implements IconRendererInterface { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Service name. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
const SERVICE_NAME = "wbw.adminbsb.twig.extension.ui.icon"; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Displays an AdminBSB basic icon. |
35
|
|
|
* |
36
|
|
|
* @param array $args The arguments. |
37
|
|
|
* @return string Returns the AdminBSB basic icon. |
38
|
|
|
*/ |
39
|
|
|
public function adminBSBIconBasicFunction(array $args = []): string { |
40
|
|
|
return $this->adminBSBIcon(ArrayHelper::get($args, "name"), ArrayHelper::get($args, "style")); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Displays an AdminBSB material design icon. |
45
|
|
|
* |
46
|
|
|
* @param array $args The arguments. |
47
|
|
|
* @return string Returns the AdminBSB material design icon. |
48
|
|
|
*/ |
49
|
|
|
public function adminBSBIconMaterialDesignFunction(array $args = []): string { |
50
|
|
|
return $this->adminBSBIcon(ArrayHelper::get($args, "name"), ArrayHelper::get($args, "style"), static::materialDesignColor(ArrayHelper::get($args, "color"), "col-")); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get the Twig functions. |
55
|
|
|
* |
56
|
|
|
* @return TwigFunction[] Returns the Twig functions. |
57
|
|
|
*/ |
58
|
|
|
public function getFunctions(): array { |
59
|
|
|
return [ |
60
|
|
|
new TwigFunction("adminBSBIconBasic", [$this, "adminBSBIconBasicFunction"], ["is_safe" => ["html"]]), |
61
|
|
|
new TwigFunction("adminBSBIconMaterialDesign", [$this, "adminBSBIconMaterialDesignFunction"], ["is_safe" => ["html"]]), |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
public function renderIcon(?string $name, ?string $style): string { |
69
|
|
|
return $this->adminBSBIconBasicFunction(["name" => $name, "style" => $style]); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|