bootstrapDropdownButton()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 4
nc 8
nop 4
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 WBW\Bundle\BootstrapBundle\Button\ButtonEnumerator;
15
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractTwigExtension;
16
use WBW\Library\Core\Argument\Helper\StringHelper;
17
18
/**
19
 * Abstract dropdown Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component
23
 * @abstract
24
 */
25
abstract class AbstractDropdownTwigExtension extends AbstractTwigExtension {
26
27
    /**
28
     * Displays a Bootstrap dropdown "button".
29
     *
30
     * @param string|null $content The content.
31
     * @param string|null $id The id.
32
     * @param bool|null $expanded Expanded ?
33
     * @param string|null $class The class.
34
     * @return string Returns the Bootstrap dropdown "button".
35
     */
36
    protected function bootstrapDropdownButton(?string $content, ?string $id, ?bool $expanded, ?string $class): string {
37
38
        $classes = ButtonEnumerator::enumTypes();
39
40
        $attributes = [];
41
42
        $attributes["class"][]         = "btn";
43
        $attributes["class"][]         = true === in_array($class, $classes) ? "btn-" . $class : "btn-default";
44
        $attributes["class"][]         = "dropdown-toggle";
45
        $attributes["type"][]          = "button";
46
        $attributes["id"][]            = null !== $id ? $id : "";
47
        $attributes["data-toggle"][]   = "dropdown";
48
        $attributes["aria-haspopup"][] = "true";
49
        $attributes["aria-expanded"][] = StringHelper::parseBoolean($expanded);
50
51
        $innerHTML = (null !== $content ? $content : "") . '<span class="caret"></span>';
52
53
        return static::coreHTMLElement("button", $innerHTML, $attributes);
54
    }
55
56
    /**
57
     * Displays a Bootstrap dropdown "divider".
58
     *
59
     * @return string Returns the Bootstrap dropdown "divider".
60
     */
61
    protected function bootstrapDropdownDivider(): string {
62
63
        $attributes = [];
64
65
        $attributes["class"] = "divider";
66
        $attributes["role"]  = "separator";
67
68
        return static::coreHTMLElement("li", null, $attributes);
69
    }
70
71
    /**
72
     * Displays a Bootstrap dropdown "header".
73
     *
74
     * @param string|null $content The content.
75
     * @return string Returns the Bootstrap dropdown "header".
76
     */
77
    protected function bootstrapDropdownHeader(?string $content): string {
78
79
        $attributes = [];
80
81
        $attributes["class"] = "dropdown-header";
82
83
        return static::coreHTMLElement("li", $content, $attributes);
84
    }
85
}
86