|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the bootstrap-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\BootstrapBundle\Twig\Extension\Component; |
|
13
|
|
|
|
|
14
|
|
|
use Twig\TwigFunction; |
|
15
|
|
|
use WBW\Bundle\BootstrapBundle\BootstrapInterface; |
|
16
|
|
|
use WBW\Library\Core\Argument\ArrayHelper; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Label Twig extension. |
|
20
|
|
|
* |
|
21
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
22
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component |
|
23
|
|
|
* @link https://getbootstrap.com/docs/3.3/components/#labels |
|
24
|
|
|
*/ |
|
25
|
|
|
class LabelTwigExtension extends AbstractLabelTwigExtension { |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Service name. |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
const SERVICE_NAME = "wbw.bootstrap.twig.extension.component.label"; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Displays a Bootstrap label "danger". |
|
36
|
|
|
* |
|
37
|
|
|
* @param array $args The arguments. |
|
38
|
|
|
* @return string Returns the Bootstrap label "danger". |
|
39
|
|
|
*/ |
|
40
|
|
|
public function bootstrapLabelDangerFunction(array $args = []) { |
|
41
|
|
|
return $this->bootstrapLabel(ArrayHelper::get($args, "content"), "label-" . BootstrapInterface::BOOTSTRAP_DANGER); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Displays a Bootstrap label "default". |
|
46
|
|
|
* |
|
47
|
|
|
* @param array $args The arguments. |
|
48
|
|
|
* @return string Returns the Bootstrap label "default". |
|
49
|
|
|
*/ |
|
50
|
|
|
public function bootstrapLabelDefaultFunction(array $args = []) { |
|
51
|
|
|
return $this->bootstrapLabel(ArrayHelper::get($args, "content"), "label-" . BootstrapInterface::BOOTSTRAP_DEFAULT); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Displays a Bootstrap label "info". |
|
56
|
|
|
* |
|
57
|
|
|
* @param array $args The arguments. |
|
58
|
|
|
* @return string Returns the Bootstrap label "info". |
|
59
|
|
|
*/ |
|
60
|
|
|
public function bootstrapLabelInfoFunction(array $args = []) { |
|
61
|
|
|
return $this->bootstrapLabel(ArrayHelper::get($args, "content"), "label-" . BootstrapInterface::BOOTSTRAP_INFO); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Displays a Bootstrap label "primary". |
|
66
|
|
|
* |
|
67
|
|
|
* @param array $args The arguments. |
|
68
|
|
|
* @return string Returns the Bootstrap label "primary". |
|
69
|
|
|
*/ |
|
70
|
|
|
public function bootstrapLabelPrimaryFunction(array $args = []) { |
|
71
|
|
|
return $this->bootstrapLabel(ArrayHelper::get($args, "content"), "label-" . BootstrapInterface::BOOTSTRAP_PRIMARY); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Displays a Bootstrap label "success". |
|
76
|
|
|
* |
|
77
|
|
|
* @param array $args The arguments. |
|
78
|
|
|
* @return string Returns the Bootstrap label "success". |
|
79
|
|
|
*/ |
|
80
|
|
|
public function bootstrapLabelSuccessFunction(array $args = []) { |
|
81
|
|
|
return $this->bootstrapLabel(ArrayHelper::get($args, "content"), "label-" . BootstrapInterface::BOOTSTRAP_SUCCESS); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Displays a Bootstrap label "warning". |
|
86
|
|
|
* |
|
87
|
|
|
* @param array $args The arguments. |
|
88
|
|
|
* @return string Returns the Bootstrap label "warning". |
|
89
|
|
|
*/ |
|
90
|
|
|
public function bootstrapLabelWarningFunction(array $args = []) { |
|
91
|
|
|
return $this->bootstrapLabel(ArrayHelper::get($args, "content"), "label-" . BootstrapInterface::BOOTSTRAP_WARNING); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Get the Twig functions. |
|
96
|
|
|
* |
|
97
|
|
|
* @return TwigFunction[] Returns the Twig functions. |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getFunctions() { |
|
100
|
|
|
if (3 === $this->getVersion()) { |
|
101
|
|
|
return $this->getFunctions3(); |
|
102
|
|
|
} |
|
103
|
|
|
return []; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Get the Twig functions. |
|
108
|
|
|
* |
|
109
|
|
|
* @return TwigFunction[] Returns the Twig functions. |
|
110
|
|
|
*/ |
|
111
|
|
|
protected function getFunctions3() { |
|
112
|
|
|
return [ |
|
113
|
|
|
new TwigFunction("bootstrapLabelDanger", [$this, "bootstrapLabelDangerFunction"], ["is_safe" => ["html"]]), |
|
114
|
|
|
new TwigFunction("bsLabelDanger", [$this, "bootstrapLabelDangerFunction"], ["is_safe" => ["html"]]), |
|
115
|
|
|
|
|
116
|
|
|
new TwigFunction("bootstrapLabelDefault", [$this, "bootstrapLabelDefaultFunction"], ["is_safe" => ["html"]]), |
|
117
|
|
|
new TwigFunction("bsLabelDefault", [$this, "bootstrapLabelDefaultFunction"], ["is_safe" => ["html"]]), |
|
118
|
|
|
|
|
119
|
|
|
new TwigFunction("bootstrapLabelInfo", [$this, "bootstrapLabelInfoFunction"], ["is_safe" => ["html"]]), |
|
120
|
|
|
new TwigFunction("bsLabelInfo", [$this, "bootstrapLabelInfoFunction"], ["is_safe" => ["html"]]), |
|
121
|
|
|
|
|
122
|
|
|
new TwigFunction("bootstrapLabelPrimary", [$this, "bootstrapLabelPrimaryFunction"], ["is_safe" => ["html"]]), |
|
123
|
|
|
new TwigFunction("bsLabelPrimary", [$this, "bootstrapLabelPrimaryFunction"], ["is_safe" => ["html"]]), |
|
124
|
|
|
|
|
125
|
|
|
new TwigFunction("bootstrapLabelSuccess", [$this, "bootstrapLabelSuccessFunction"], ["is_safe" => ["html"]]), |
|
126
|
|
|
new TwigFunction("bsLabelSuccess", [$this, "bootstrapLabelSuccessFunction"], ["is_safe" => ["html"]]), |
|
127
|
|
|
|
|
128
|
|
|
new TwigFunction("bootstrapLabelWarning", [$this, "bootstrapLabelWarningFunction"], ["is_safe" => ["html"]]), |
|
129
|
|
|
new TwigFunction("bsLabelWarning", [$this, "bootstrapLabelWarningFunction"], ["is_safe" => ["html"]]), |
|
130
|
|
|
]; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|