Completed
Push — master ( 7d0ef3...14c63c )
by WEBEWEB
03:01
created

bootstrapDropdownDivider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
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 WBW\Bundle\BootstrapBundle\BootstrapBundle;
15
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractBootstrapTwigExtension;
16
use WBW\Library\Core\Utility\Argument\StringUtility;
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 AbstractBootstrapTwigExtension {
26
27
    /**
28
     * Constructor.
29
     */
30
    protected function __construct() {
31
        parent::__construct();
32
    }
33
34
    /**
35
     * Displays a Bootstrap dropdown "Button".
36
     *
37
     * @param string $content The content.
38
     * @param string $id The id.
39
     * @param boolean $expanded Expanded ?
40
     * @param string $class The class.
41
     * @return string Returns the Bootstrap dropdown "Button".
42
     */
43
    protected function bootstrapDropdownButton($content, $id, $expanded, $class) {
44
45
        // Initailize the values.
46
        $classes = BootstrapBundle::getBootstrapConstants();
47
48
        // Initialize the attributes.
49
        $attributes = [];
50
51
        $attributes["class"][]         = "btn";
52
        $attributes["class"][]         = true === in_array($class, $classes) ? "btn-" . $class : "btn-default";
53
        $attributes["class"][]         = "dropdown-toggle";
54
        $attributes["type"][]          = "button";
55
        $attributes["id"][]            = null !== $id ? $id : "";
56
        $attributes["data-toggle"][]   = "dropdown";
57
        $attributes["aria-haspopup"][] = "true";
58
        $attributes["aria-expanded"][] = StringUtility::parseBoolean($expanded);
59
60
        // Initialize the parameters.
61
        $innerHTML = (null !== $content ? $content : "") . "<span class=\"caret\"></span>";
62
63
        // Return the HTML.
64
        return self::bootstrapHTMLElement("button", $innerHTML, $attributes);
65
    }
66
67
    /**
68
     * Displays a Bootstrap dropdown "Divider".
69
     *
70
     * @return string Returns the Bootstrap dropdown "Divider".
71
     */
72
    protected function bootstrapDropdownDivider() {
73
74
        // Initialize the attributes.
75
        $attributes = [];
76
77
        $attributes["class"] = "divider";
78
        $attributes["role"]  = "separator";
79
80
        // Return the HTML.
81
        return self::bootstrapHTMLElement("li", null, $attributes);
82
    }
83
84
    /**
85
     * Displays a Bootstrap dropdown "Header".
86
     *
87
     * @param string $content The content.
88
     * @return string Returns the Bootstrap dropdown "Header".
89
     */
90
    protected function bootstrapDropdownHeader($content) {
91
92
        // Initialize the attributes.
93
        $attributes = [];
94
95
        $attributes["class"] = "dropdown-header";
96
97
        // Return the HTML.
98
        return self::bootstrapHTMLElement("li", $content, $attributes);
99
    }
100
101
}
102