Completed
Push — master ( a27d66...168bdb )
by WEBEWEB
05:24
created

AlertTwigExtension::bootstrapAlertDarkFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\Alert\AlertFactory;
16
use WBW\Bundle\CoreBundle\Navigation\NavigationInterface;
17
use WBW\Library\Core\Argument\ArrayHelper;
18
19
/**
20
 * Alert Twig extension.
21
 *
22
 * @author webeweb <https://github.com/webeweb/>
23
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component
24
 * @link https://getbootstrap.com/docs/3.3/components/#alerts
25
 */
26
class AlertTwigExtension extends AbstractAlertTwigExtension {
27
28
    /**
29
     * Service name.
30
     *
31
     * @var string
32
     */
33
    const SERVICE_NAME = "wbw.bootstrap.twig.extension.component.alert";
34
35
    /**
36
     * Displays a Bootstrap alert "danger".
37
     *
38
     * @param array $args The arguments.
39
     * @return string Returns the Bootstrap alert "danger".
40
     */
41
    public function bootstrapAlertDangerFunction(array $args = []) {
42
        return $this->bootstrapAlert(AlertFactory::parseDangerAlert($args));
43
    }
44
45
    /**
46
     * Displays a Bootstrap alert "dark".
47
     *
48
     * @param array $args The arguments.
49
     * @return string Returns the Bootstrap alert "dark".
50
     */
51
    public function bootstrapAlertDarkFunction(array $args = []) {
52
        return $this->bootstrapAlert(AlertFactory::parseDarkAlert($args));
53
    }
54
55
    /**
56
     * Displays a Bootstrap alert "info".
57
     *
58
     * @param array $args The arguments.
59
     * @return string Returns the Bootstrap alert "info".
60
     */
61
    public function bootstrapAlertInfoFunction(array $args = []) {
62
        return $this->bootstrapAlert(AlertFactory::parseInfoAlert($args));
63
    }
64
65
    /**
66
     * Displays a Bootstrap alert "light".
67
     *
68
     * @param array $args The arguments.
69
     * @return string Returns the Bootstrap alert "light".
70
     */
71
    public function bootstrapAlertLightFunction(array $args = []) {
72
        return $this->bootstrapAlert(AlertFactory::parseLightAlert($args));
73
    }
74
75
    /**
76
     * Displays a Bootstrap alert "link".
77
     *
78
     * @param array $args The arguments.
79
     * @return string Returns the Bootstrap alert "link".
80
     */
81
    public function bootstrapAlertLinkFunction(array $args = []) {
82
83
        $attributes = [];
84
85
        $attributes["href"] = ArrayHelper::get($args, "href", NavigationInterface::NAVIGATION_HREF_DEFAULT);
86
87
        $innerHTML = ArrayHelper::get($args, "content");
88
89
        return static::coreHTMLElement("a", $innerHTML, $attributes);
90
    }
91
92
    /**
93
     * Displays a Bootstrap alert "secondary".
94
     *
95
     * @param array $args The arguments.
96
     * @return string Returns the Bootstrap alert "secondary".
97
     */
98
    public function bootstrapAlertSecondaryFunction(array $args = []) {
99
        return $this->bootstrapAlert(AlertFactory::parseSecondaryAlert($args));
100
    }
101
102
    /**
103
     * Displays a Bootstrap alert "success".
104
     *
105
     * @param array $args The arguments.
106
     * @return string Returns the Bootstrap alert "success".
107
     */
108
    public function bootstrapAlertSuccessFunction(array $args = []) {
109
        return $this->bootstrapAlert(AlertFactory::parseSuccessAlert($args));
110
    }
111
112
    /**
113
     * Displays a Bootstrap alert "warning".
114
     *
115
     * @param array $args The arguments.
116
     * @return string Returns the Bootstrap alert "warning".
117
     */
118
    public function bootstrapAlertWarningFunction(array $args = []) {
119
        return $this->bootstrapAlert(AlertFactory::parseWarningAlert($args));
120
    }
121
122
    /**
123
     * Get the Twig functions.
124
     *
125
     * @return TwigFunction[] Returns the Twig functions.
126
     */
127
    public function getFunctions() {
128
        return [
129
            new TwigFunction("bootstrapAlertDanger", [$this, "bootstrapAlertDangerFunction"], ["is_safe" => ["html"]]),
130
            new TwigFunction("bsAlertDanger", [$this, "bootstrapAlertDangerFunction"], ["is_safe" => ["html"]]),
131
132
            new TwigFunction("bootstrapAlertDark", [$this, "bootstrapAlertDarkFunction"], ["is_safe" => ["html"]]),
133
            new TwigFunction("bsAlertDark", [$this, "bootstrapAlertDarkFunction"], ["is_safe" => ["html"]]),
134
135
            new TwigFunction("bootstrapAlertInfo", [$this, "bootstrapAlertInfoFunction"], ["is_safe" => ["html"]]),
136
            new TwigFunction("bsAlertInfo", [$this, "bootstrapAlertInfoFunction"], ["is_safe" => ["html"]]),
137
138
            new TwigFunction("bootstrapAlertLight", [$this, "bootstrapAlertLightFunction"], ["is_safe" => ["html"]]),
139
            new TwigFunction("bsAlertLight", [$this, "bootstrapAlertLightFunction"], ["is_safe" => ["html"]]),
140
141
            new TwigFunction("bootstrapAlertLink", [$this, "bootstrapAlertLinkFunction"], ["is_safe" => ["html"]]),
142
            new TwigFunction("bsAlertLink", [$this, "bootstrapAlertLinkFunction"], ["is_safe" => ["html"]]),
143
144
            new TwigFunction("bootstrapAlertSecondary", [$this, "bootstrapAlertSecondaryFunction"], ["is_safe" => ["html"]]),
145
            new TwigFunction("bsAlertSecondary", [$this, "bootstrapAlertSecondaryFunction"], ["is_safe" => ["html"]]),
146
147
            new TwigFunction("bootstrapAlertSuccess", [$this, "bootstrapAlertSuccessFunction"], ["is_safe" => ["html"]]),
148
            new TwigFunction("bsAlertSuccess", [$this, "bootstrapAlertSuccessFunction"], ["is_safe" => ["html"]]),
149
150
            new TwigFunction("bootstrapAlertWarning", [$this, "bootstrapAlertWarningFunction"], ["is_safe" => ["html"]]),
151
            new TwigFunction("bsAlertWarning", [$this, "bootstrapAlertWarningFunction"], ["is_safe" => ["html"]]),
152
        ];
153
    }
154
}
155