|
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 WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractBootstrapTwigExtension; |
|
15
|
|
|
use WBW\Bundle\BootstrapBundle\Twig\Extension\BootstrapRendererTwigExtension; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Abstract button Twig extension. |
|
19
|
|
|
* |
|
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
21
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\CSS |
|
22
|
|
|
* @abstract |
|
23
|
|
|
*/ |
|
24
|
|
|
abstract class AbstractButtonTwigExtension extends AbstractBootstrapTwigExtension { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Constructor. |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function __construct() { |
|
30
|
|
|
parent::__construct(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Displays a Bootstrap button. |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $content The content. |
|
37
|
|
|
* @param string $title The title. |
|
38
|
|
|
* @param string $size The size. |
|
39
|
|
|
* @param boolean $block Block ? |
|
40
|
|
|
* @param booelan $active Active ? |
|
41
|
|
|
* @param booelan $disable Disable ? |
|
42
|
|
|
* @param string $class The class. |
|
43
|
|
|
* @param string $icon The icon. |
|
44
|
|
|
* @return string Returns the Bootstrap button. |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function bootstrapButton($content, $title, $size, $block, $active, $disable, $class, $icon) { |
|
47
|
|
|
|
|
48
|
|
|
// Initialize the attributes. |
|
49
|
|
|
$attributes = []; |
|
50
|
|
|
|
|
51
|
|
|
$attributes["class"] = ["btn", $class]; |
|
52
|
|
|
$attributes["class"][] = true === $block ? "btn-block" : null; |
|
53
|
|
|
$attributes["class"][] = true === in_array($size, ["lg", "sm", "xs"]) ? "btn-" . $size : null; |
|
54
|
|
|
$attributes["class"][] = true === $active ? "active" : null; |
|
55
|
|
|
$attributes["title"] = $title; |
|
56
|
|
|
$attributes["type"] = "button"; |
|
57
|
|
|
$attributes["data-toggle"] = null !== $title ? "tooltip" : null; |
|
58
|
|
|
$attributes["data-placement"] = null !== $title ? "top" : null; |
|
59
|
|
|
$attributes["disabled"] = true === $disable ? "disabled" : null; |
|
60
|
|
|
|
|
61
|
|
|
// Handle the parameters. |
|
62
|
|
|
$glyphicon = null !== $icon ? BootstrapRendererTwigExtension::renderIcon($icon) : ""; |
|
63
|
|
|
$innerHTML = null !== $content ? $content : ""; |
|
64
|
|
|
|
|
65
|
|
|
// Return the HTML. |
|
66
|
|
|
return self::bootstrapHTMLElement("button", implode(" ", [$glyphicon, $innerHTML]), $attributes); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|