1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the adminbsb-material-design-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\AdminBSBBundle\Twig\Extension\UI; |
13
|
|
|
|
14
|
|
|
use WBW\Bundle\AdminBSBBundle\Button\ButtonRenderer; |
15
|
|
|
use WBW\Bundle\AdminBSBBundle\Twig\Extension\RendererTwigExtension; |
16
|
|
|
use WBW\Bundle\BootstrapBundle\Button\ButtonInterface; |
17
|
|
|
use WBW\Bundle\BootstrapBundle\Twig\Extension\CSS\ButtonTwigExtension as BaseTwigExtension; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Abstract button Twig extension. |
21
|
|
|
* |
22
|
|
|
* @author webeweb <https://github.com/webeweb/> |
23
|
|
|
* @package WBW\Bundle\AdminBSBBundle\Twig\Extension\UI |
24
|
|
|
* @abstract |
25
|
|
|
*/ |
26
|
|
|
abstract class AbstractButtonTwigExtension extends BaseTwigExtension { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Displays an AdminBSB button. |
30
|
|
|
* |
31
|
|
|
* @param ButtonInterface $button The button. |
32
|
|
|
* @param string|null $icon The icon. |
33
|
|
|
* @param bool $circle Circle ? |
34
|
|
|
* @return string Returns the AdminBSB button. |
35
|
|
|
*/ |
36
|
|
|
protected function adminBSBButton(ButtonInterface $button, ?string $icon, bool $circle): string { |
37
|
|
|
|
38
|
|
|
// Fix some parameters. |
39
|
|
|
$circle = null !== $button->getContent() ? false : $circle; |
40
|
|
|
$style = null !== $button->getContent() ? "margin: -4px 2px 0; vertical-align: sub;" : ""; |
41
|
|
|
|
42
|
|
|
$attributes = []; |
43
|
|
|
|
44
|
|
|
$attributes["class"] = ["btn", ButtonRenderer::renderType($button), "waves-effect"]; |
45
|
|
|
$attributes["class"][] = ButtonRenderer::renderBlock($button); |
46
|
|
|
$attributes["class"][] = ButtonRenderer::renderCircle($button, $circle); |
47
|
|
|
$attributes["title"] = ButtonRenderer::renderTitle($button); |
48
|
|
|
$attributes["type"] = "button"; |
49
|
|
|
$attributes["data-toggle"] = ButtonRenderer::renderDataToggle($button); |
50
|
|
|
$attributes["data-placement"] = ButtonRenderer::renderDataPlacement($button); |
51
|
|
|
$attributes["disabled"] = ButtonRenderer::renderDisabled($button); |
52
|
|
|
|
53
|
|
|
$glyphicon = null !== $icon ? RendererTwigExtension::renderIcon($this->getTwigEnvironment(), $icon, $style) : ""; |
|
|
|
|
54
|
|
|
$innerHTML = ButtonRenderer::renderContent($button); |
55
|
|
|
|
56
|
|
|
return static::coreHTMLElement("button", $glyphicon . $innerHTML, $attributes); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
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: