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\Assets; |
13
|
|
|
|
14
|
|
|
use Twig\TwigFunction; |
15
|
|
|
use WBW\Library\Symfony\Renderer\Assets\IconRendererInterface; |
16
|
|
|
use WBW\Library\Types\Helper\ArrayHelper; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Meteocons Twig extension. |
20
|
|
|
* |
21
|
|
|
* @author webeweb <https://github.com/webeweb> |
22
|
|
|
* @package WBW\Bundle\CoreBundle\Twig\Extension\Assets |
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.assets.meteocons"; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get the Twig functions. |
35
|
|
|
* |
36
|
|
|
* @return TwigFunction[] Returns the Twig functions. |
37
|
|
|
*/ |
38
|
|
|
public function getFunctions(): array { |
39
|
|
|
|
40
|
|
|
return [ |
41
|
|
|
new TwigFunction("meteoconsIcon", [$this, "meteoconsIconFunction"], ["is_safe" => ["html"]]), |
42
|
|
|
]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Display a Meteocons icon. |
47
|
|
|
* |
48
|
|
|
* @param array $args The arguments. |
49
|
|
|
* @return string Returns a Meteocons icon. |
50
|
|
|
*/ |
51
|
|
|
public function meteoconsIconFunction(array $args = []): string { |
52
|
|
|
return $this->meteoconsIcon(ArrayHelper::get($args, "name", "A"), ArrayHelper::get($args, "style")); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritDoc} |
57
|
|
|
*/ |
58
|
|
|
public function renderIcon(?string $name, ?string $style): string { |
59
|
|
|
return $this->meteoconsIconFunction(["name" => $name, "style" => $style]); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|