|
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\Twig\Extension\AbstractTwigExtension; |
|
15
|
|
|
use WBW\Library\Core\Argument\Helper\StringHelper; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Abstract badge Twig extension. |
|
19
|
|
|
* |
|
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
21
|
|
|
* @package WBW\Bundle\AdminBSBBundle\Twig\Extension\UI |
|
22
|
|
|
* @abstract |
|
23
|
|
|
*/ |
|
24
|
|
|
abstract class AbstractBadgeTwigExtension extends AbstractTwigExtension { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Displays an AdminBSB badge. |
|
28
|
|
|
* |
|
29
|
|
|
* @param string|null $content The content. |
|
30
|
|
|
* @param string|null $label The label. |
|
31
|
|
|
* @param bool $large Large ? |
|
32
|
|
|
* @param string $class The class. |
|
33
|
|
|
* @param bool $list List ? |
|
34
|
|
|
* @param string|null $link The link. |
|
35
|
|
|
* @return string Returns the AdminBSB badge. |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function adminBSBBadge(?string $content, ?string $label, bool $large, string $class, bool $list = false, string $link = null): string { |
|
38
|
|
|
|
|
39
|
|
|
$template = '<button %attributes%>%innerHTML%<span class="badge">%label%</span></button>'; |
|
40
|
|
|
if (true === $list) { |
|
41
|
|
|
$template = '<a class="list-group-item" href="%href%"><span %attributes%>%innerHTML%</span>%label%</a>'; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$attributes = []; |
|
45
|
|
|
|
|
46
|
|
|
if (true === $list) { |
|
47
|
|
|
$attributes["class"] = ["badge", $class]; |
|
48
|
|
|
} else { |
|
49
|
|
|
$attributes["class"] = ["btn", $class, "btn-block", "waves-effect"]; |
|
50
|
|
|
$attributes["class"][] = true === $large ? "btn-lg" : null; |
|
51
|
|
|
$attributes["type"] = "button"; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$innerHTML = null !== $content ? $content : ""; |
|
55
|
|
|
$spanLabel = null !== $label ? $label : ""; |
|
56
|
|
|
$href = null !== $link ? $link : self::DEFAULT_HREF; |
|
57
|
|
|
|
|
58
|
|
|
return str_replace(["%attributes%", "%innerHTML%", "%label%", "%href%"], [StringHelper::parseArray($attributes), $innerHTML, $spanLabel, $href], $template); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|