DropdownTwigExtension::getFunctions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Library\Core\Argument\Helper\ArrayHelper;
16
17
/**
18
 * Dropdown Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component
22
 * @link https://getbootstrap.com/docs/3.3/components/#dropdowns
23
 */
24
class DropdownTwigExtension extends AbstractDropdownTwigExtension {
25
26
    /**
27
     * Service name.
28
     *
29
     * @var string
30
     */
31
    const SERVICE_NAME = "wbw.bootstrap.twig.extension.component.dropdown";
32
33
    /**
34
     * Displays a Bootstrap dropdown "button".
35
     *
36
     * @param array $args The arguments.
37
     * @return string Returns the Bootstrap dropdown "button".
38
     */
39
    public function bootstrapDropdownButtonFunction(array $args = []): string {
40
        return $this->bootstrapDropdownButton(ArrayHelper::get($args, "content"), ArrayHelper::get($args, "id"), ArrayHelper::get($args, "expanded", true), ArrayHelper::get($args, "class", "default"));
41
    }
42
43
    /**
44
     * Displays a Bootstrap dropdown "divider".
45
     *
46
     * @return string Returns the Bootstrap dropdown "divider".
47
     */
48
    public function bootstrapDropdownDividerFunction(): string {
49
        return $this->bootstrapDropdownDivider();
50
    }
51
52
    /**
53
     * Displays a Bootstrap dropdown "header".
54
     *
55
     * @param array $args The arguments.
56
     * @return string Returns the Bootstrap dropdown "header".
57
     */
58
    public function bootstrapDropdownHeaderFunction(array $args = []): string {
59
        return $this->bootstrapDropdownHeader(ArrayHelper::get($args, "content"));
60
    }
61
62
    /**
63
     * Get the Twig functions.
64
     *
65
     * @return TwigFunction[] Returns the Twig functions.
66
     */
67
    public function getFunctions(): array {
68
        return [
69
            new TwigFunction("bootstrapDropdownButton", [$this, "bootstrapDropdownButtonFunction"], ["is_safe" => ["html"]]),
70
            new TwigFunction("bsDropdownButton", [$this, "bootstrapDropdownButtonFunction"], ["is_safe" => ["html"]]),
71
72
            new TwigFunction("bootstrapDropdownDivider", [$this, "bootstrapDropdownDividerFunction"], ["is_safe" => ["html"]]),
73
            new TwigFunction("bsDropdownDivider", [$this, "bootstrapDropdownDividerFunction"], ["is_safe" => ["html"]]),
74
75
            new TwigFunction("bootstrapDropdownHeader", [$this, "bootstrapDropdownHeaderFunction"], ["is_safe" => ["html"]]),
76
            new TwigFunction("bsDropdownHeader", [$this, "bootstrapDropdownHeaderFunction"], ["is_safe" => ["html"]]),
77
        ];
78
    }
79
}
80