1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the core-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\CoreBundle\Twig\Extension\Asset; |
13
|
|
|
|
14
|
|
|
use Twig\TwigFunction; |
15
|
|
|
use WBW\Bundle\CoreBundle\Renderer\IconRendererInterface; |
16
|
|
|
use WBW\Library\Core\Argument\ArrayHelper; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Meteocons Twig extension. |
20
|
|
|
* |
21
|
|
|
* @author webeweb <https://github.com/webeweb/> |
22
|
|
|
* @package WBW\Bundle\CoreBundle\Twig\Extension\Asset |
23
|
|
|
*/ |
24
|
|
|
class MeteoconsTwigExtension extends AbstractMeteoconsTwigExtension implements IconRendererInterface { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Service name. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
const SERVICE_NAME = "wbw.core.twig.extension.asset.meteocons"; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get the Twig functions. |
35
|
|
|
* |
36
|
|
|
* @return TwigFunction[] Returns the Twig functions. |
37
|
|
|
*/ |
38
|
|
|
public function getFunctions() { |
39
|
|
|
return [ |
40
|
|
|
new TwigFunction("meteoconsIcon", [$this, "meteoconsIconFunction"], ["is_safe" => ["html"]]), |
41
|
|
|
]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Displays a Meteocons icon. |
46
|
|
|
* |
47
|
|
|
* @param array $args The arguments. |
48
|
|
|
* @return string Returns a Meteocons icon. |
49
|
|
|
*/ |
50
|
|
|
public function meteoconsIconFunction(array $args = []) { |
51
|
|
|
return $this->meteoconsIcon(ArrayHelper::get($args, "name", "A"), ArrayHelper::get($args, "style")); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritDoc} |
56
|
|
|
*/ |
57
|
|
|
public function renderIcon($name, $style) { |
58
|
|
|
return $this->meteoconsIconFunction(["name" => $name, "style" => $style]); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|