Completed
Push — master ( fdbfc2...a2832c )
by WEBEWEB
02:08
created

AbstractButtonTwigExtension::bootstrapButton()   A

Complexity

Conditions 2
Paths 2

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 2
nc 2
nop 2
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\CSS;
13
14
use Twig_Environment;
15
use WBW\Bundle\BootstrapBundle\Button\ButtonInterface;
16
use WBW\Bundle\BootstrapBundle\Button\ButtonRenderer;
17
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractTwigExtension;
18
use WBW\Bundle\BootstrapBundle\Twig\Extension\RendererTwigExtension;
19
20
/**
21
 * Abstract button Twig extension.
22
 *
23
 * @author webeweb <https://github.com/webeweb/>
24
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\CSS
25
 * @abstract
26
 */
27
abstract class AbstractButtonTwigExtension extends AbstractTwigExtension {
28
29
    /**
30
     * Constructor.
31
     *
32
     * @param Twig_Environment $twigEnvironment The Twig environment.
33
     */
34
    protected function __construct(Twig_Environment $twigEnvironment) {
35
        parent::__construct($twigEnvironment);
36
    }
37
38
    /**
39
     * Displays a Bootstrap button.
40
     *
41
     * @param ButtonInterface $button The button.
42
     * @param string $icon The icon.
43
     * @return string Returns the Bootstrap button.
44
     */
45
    protected function bootstrapButton(ButtonInterface $button, $icon) {
46
47
        $attributes = [];
48
49
        $attributes["class"]          = ["btn", ButtonRenderer::renderType($button)];
50
        $attributes["class"][]        = ButtonRenderer::renderBlock($button);
51
        $attributes["class"][]        = ButtonRenderer::renderSize($button);
52
        $attributes["class"][]        = ButtonRenderer::renderActive($button);
53
        $attributes["title"]          = ButtonRenderer::renderTitle($button);
54
        $attributes["type"]           = "button";
55
        $attributes["data-toggle"]    = ButtonRenderer::renderDataToggle($button);
56
        $attributes["data-placement"] = ButtonRenderer::renderDataPLacement($button);
57
        $attributes["disabled"]       = ButtonRenderer::renderDisabled($button);
58
59
        $glyphicon = null !== $icon ? RendererTwigExtension::renderIcon($this->getTwigEnvironment(), $icon) : "";
60
        $innerHTML = ButtonRenderer::renderContent($button);
61
62
        return static::coreHTMLElement("button", implode(" ", [$glyphicon, $innerHTML]), $attributes);
63
    }
64
}
65