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\AbstractAdminBSBTwigExtension; |
15
|
|
|
use WBW\Library\Core\Utility\Argument\StringUtility; |
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 AbstractAdminBSBTwigExtension { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Constructor. |
28
|
|
|
*/ |
29
|
|
|
protected function __construct() { |
30
|
|
|
parent::__construct(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Displays an AdminBSB badge. |
35
|
|
|
* |
36
|
|
|
* @param string $content The content. |
37
|
|
|
* @param string $label The label. |
38
|
|
|
* @param boolean $large Large ? |
39
|
|
|
* @param string $class The class. |
40
|
|
|
* @param boolean $list List ? |
41
|
|
|
* @param string $link The link. |
42
|
|
|
* @return string Returns the AdminBSB badge. |
43
|
|
|
*/ |
44
|
|
|
protected function adminBSBBadge($content, $label, $large, $class, $list = false, $link = false) { |
45
|
|
|
|
46
|
|
|
// Initialize the template. |
47
|
|
|
$template = '<button %attributes%>%innerHTML%<span class="badge">%label%</span></button>'; |
48
|
|
|
if (true === $list) { |
49
|
|
|
$template = '<a class="list-group-item" href="%href%"><span %attributes%>%innerHTML%</span>%label%</a>'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// Initialize the attributes. |
53
|
|
|
$attributes = []; |
54
|
|
|
|
55
|
|
|
if (true === $list) { |
56
|
|
|
$attributes["class"] = ["badge", $class]; |
57
|
|
|
} else { |
58
|
|
|
$attributes["class"] = ["btn", $class, "btn-block", "waves-effect"]; |
59
|
|
|
$attributes["class"][] = true === $large ? "btn-lg" : null; |
60
|
|
|
$attributes["type"] = "button"; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// Initialize the parameters. |
64
|
|
|
$innerHTML = null !== $content ? $content : ""; |
65
|
|
|
$spanLabel = null !== $label ? $label : ""; |
66
|
|
|
$href = null !== $link ? $link : self::DEFAULT_HREF; |
67
|
|
|
|
68
|
|
|
// Return the HTML. |
69
|
|
|
return StringUtility::replace($template, ["%attributes%", "%innerHTML%", "%label%", "%href%"], [StringUtility::parseArray($attributes), $innerHTML, $spanLabel, $href]); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
|