|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the adminbsb-material-design-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2018 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; |
|
13
|
|
|
|
|
14
|
|
|
use Twig_Environment; |
|
15
|
|
|
use Twig_SimpleFilter; |
|
16
|
|
|
use WBW\Bundle\AdminBSBBundle\Twig\Extension\UI\IconTwigExtension; |
|
17
|
|
|
use WBW\Bundle\BootstrapBundle\Twig\Extension\RendererTwigExtension as BaseTwigExtension; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Renderer Twig extension. |
|
21
|
|
|
* |
|
22
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
23
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension |
|
24
|
|
|
*/ |
|
25
|
|
|
class RendererTwigExtension extends BaseTwigExtension { |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Service name. |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
const SERVICE_NAME = "webeweb.adminbsb.twig.extension.renderer"; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Constructor. |
|
36
|
|
|
* |
|
37
|
|
|
* @param Twig_Environment $twigEnvironment The twig environment. |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(Twig_Environment $twigEnvironment) { |
|
40
|
|
|
parent::__construct($twigEnvironment); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get the Twig filters. |
|
45
|
|
|
* |
|
46
|
|
|
* @return Twig_SimpleFilter[] Returns the Twig filters. |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getFilters() { |
|
49
|
|
|
return []; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Render an icon. |
|
54
|
|
|
* |
|
55
|
|
|
* @param Twig_Environment $twigEnvironment The twig environment. |
|
56
|
|
|
* @param string $name The icon name. |
|
57
|
|
|
* @param string $style The icon style. |
|
58
|
|
|
* @return string Returns a rendered icon. |
|
59
|
|
|
*/ |
|
60
|
|
|
public static function renderIcon(Twig_Environment $twigEnvironment, $name, $style = null) { |
|
61
|
|
|
|
|
62
|
|
|
// Determines the handler. |
|
63
|
|
|
$handler = explode(":", $name); |
|
64
|
|
|
if (1 === count($handler)) { |
|
65
|
|
|
array_unshift($handler, "mi"); |
|
66
|
|
|
} |
|
67
|
|
|
if (2 !== count($handler)) { |
|
68
|
|
|
return ""; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
// Swith into handler. |
|
72
|
|
|
switch ($handler[0]) { |
|
73
|
|
|
|
|
74
|
|
|
case "mi": // Material design |
|
75
|
|
|
$output = (new IconTwigExtension($twigEnvironment))->renderIcon($handler[1], $style); |
|
76
|
|
|
break; |
|
77
|
|
|
|
|
78
|
|
|
default: |
|
79
|
|
|
$output = parent::renderIcon($twigEnvironment, $name, $style); |
|
80
|
|
|
break; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
// Return the output. |
|
84
|
|
|
return $output; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|