1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the bootstrap-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 NdC/WBW |
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\BootstrapBundle\Twig\Extension\Component; |
13
|
|
|
|
14
|
|
|
use Twig_SimpleFunction; |
15
|
|
|
use WBW\Library\Core\Utility\ArrayUtility; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Label component Twig extension. |
19
|
|
|
* |
20
|
|
|
* @author NdC/WBW <https://github.com/webeweb/> |
21
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component |
22
|
|
|
* @final |
23
|
|
|
*/ |
24
|
|
|
final class LabelComponentTwigExtension extends AbstractComponentTwigExtension { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Service name. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
const SERVICE_NAME = "webeweb.bundle.bootstrapbundle.twig.extension.component.label"; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Displays a Bootstrap label "Danger". |
35
|
|
|
* |
36
|
|
|
* @param array $args The arguments. |
37
|
|
|
* @return string Returns the Bootstrap label "Danger". |
38
|
|
|
*/ |
39
|
|
|
public function bootstrapLabelDangerFunction(array $args = []) { |
40
|
|
|
return $this->bootstrapLabel(ArrayUtility::get($args, "content"), "label-danger"); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Displays a Bootstrap label "Default". |
45
|
|
|
* |
46
|
|
|
* @param array $args The arguments. |
47
|
|
|
* @return string Returns the Bootstrap label "Default". |
48
|
|
|
*/ |
49
|
|
|
public function bootstrapLabelDefaultFunction(array $args = []) { |
50
|
|
|
return $this->bootstrapLabel(ArrayUtility::get($args, "content"), "label-default"); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Displays a Bootstrap label "Info". |
55
|
|
|
* |
56
|
|
|
* @param array $args The arguments. |
57
|
|
|
* @return string Returns the Bootstrap label "Info". |
58
|
|
|
*/ |
59
|
|
|
public function bootstrapLabelInfoFunction(array $args = []) { |
60
|
|
|
return $this->bootstrapLabel(ArrayUtility::get($args, "content"), "label-info"); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Displays a Bootstrap label "Primary". |
65
|
|
|
* |
66
|
|
|
* @param array $args The arguments. |
67
|
|
|
* @return string Returns the Bootstrap label "Primary". |
68
|
|
|
*/ |
69
|
|
|
public function bootstrapLabelPrimaryFunction(array $args = []) { |
70
|
|
|
return $this->bootstrapLabel(ArrayUtility::get($args, "content"), "label-primary"); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Displays a Bootstrap label "Success". |
75
|
|
|
* |
76
|
|
|
* @param array $args The arguments. |
77
|
|
|
* @return string Returns the Bootstrap label "Success". |
78
|
|
|
*/ |
79
|
|
|
public function bootstrapLabelSuccessFunction(array $args = []) { |
80
|
|
|
return $this->bootstrapLabel(ArrayUtility::get($args, "content"), "label-success"); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Displays a Bootstrap label "Warning". |
85
|
|
|
* |
86
|
|
|
* @param array $args The arguments. |
87
|
|
|
* @return string Returns the Bootstrap label "Warning". |
88
|
|
|
*/ |
89
|
|
|
public function bootstrapLabelWarningFunction(array $args = []) { |
90
|
|
|
return $this->bootstrapLabel(ArrayUtility::get($args, "content"), "label-warning"); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get the Twig functions. |
95
|
|
|
* |
96
|
|
|
* @return array Returns the Twig functions. |
97
|
|
|
*/ |
98
|
|
|
public function getFunctions() { |
99
|
|
|
return [ |
100
|
|
|
new Twig_SimpleFunction("bootstrapLabelDanger", [$this, "bootstrapLabelDangerFunction"], ["is_safe" => ["html"]]), |
101
|
|
|
new Twig_SimpleFunction("bootstrapLabelDefault", [$this, "bootstrapLabelDefaultFunction"], ["is_safe" => ["html"]]), |
102
|
|
|
new Twig_SimpleFunction("bootstrapLabelInfo", [$this, "bootstrapLabelInfoFunction"], ["is_safe" => ["html"]]), |
103
|
|
|
new Twig_SimpleFunction("bootstrapLabelPrimary", [$this, "bootstrapLabelPrimaryFunction"], ["is_safe" => ["html"]]), |
104
|
|
|
new Twig_SimpleFunction("bootstrapLabelSuccess", [$this, "bootstrapLabelSuccessFunction"], ["is_safe" => ["html"]]), |
105
|
|
|
new Twig_SimpleFunction("bootstrapLabelWarning", [$this, "bootstrapLabelWarningFunction"], ["is_safe" => ["html"]]), |
106
|
|
|
]; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
} |
110
|
|
|
|