|
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\Button\ButtonInterface; |
|
15
|
|
|
use WBW\Bundle\BootstrapBundle\Button\ButtonRenderer; |
|
16
|
|
|
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractTwigExtension; |
|
17
|
|
|
use WBW\Bundle\BootstrapBundle\Twig\Extension\RendererTwigExtension; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Abstract button Twig extension. |
|
21
|
|
|
* |
|
22
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
23
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\CSS |
|
24
|
|
|
* @abstract |
|
25
|
|
|
*/ |
|
26
|
|
|
abstract class AbstractButtonTwigExtension extends AbstractTwigExtension { |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Displays a Bootstrap button. |
|
30
|
|
|
* |
|
31
|
|
|
* @param ButtonInterface $button The button. |
|
32
|
|
|
* @param string|null $icon The icon. |
|
33
|
|
|
* @return string Returns the Bootstrap button. |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function bootstrapButton(ButtonInterface $button, ?string $icon): string { |
|
36
|
|
|
|
|
37
|
|
|
$attributes = []; |
|
38
|
|
|
|
|
39
|
|
|
$attributes["class"] = ["btn", ButtonRenderer::renderType($button)]; |
|
40
|
|
|
$attributes["class"][] = ButtonRenderer::renderBlock($button); |
|
41
|
|
|
$attributes["class"][] = ButtonRenderer::renderSize($button); |
|
42
|
|
|
$attributes["class"][] = ButtonRenderer::renderActive($button); |
|
43
|
|
|
$attributes["title"] = ButtonRenderer::renderTitle($button); |
|
44
|
|
|
$attributes["type"] = "button"; |
|
45
|
|
|
$attributes["data-toggle"] = ButtonRenderer::renderDataToggle($button); |
|
46
|
|
|
$attributes["data-placement"] = ButtonRenderer::renderDataPLacement($button); |
|
47
|
|
|
$attributes["disabled"] = ButtonRenderer::renderDisabled($button); |
|
48
|
|
|
|
|
49
|
|
|
$glyphicon = null !== $icon ? RendererTwigExtension::renderIcon($this->getTwigEnvironment(), $icon) : ""; |
|
|
|
|
|
|
50
|
|
|
$innerHTML = ButtonRenderer::renderContent($button); |
|
51
|
|
|
|
|
52
|
|
|
return static::coreHTMLElement("button", implode(" ", [$glyphicon, $innerHTML]), $attributes); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: