1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the adminbsb-material-design-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2017 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\Widget; |
13
|
|
|
|
14
|
|
|
use Twig_SimpleFunction; |
15
|
|
|
use WBW\Bundle\AdminBSBBundle\Twig\Extension\Typography\HeadingTypographyTwigExtension; |
16
|
|
|
use WBW\Bundle\AdminBSBBundle\Twig\Extension\UI\IconUITwigExtension; |
17
|
|
|
use WBW\Library\Core\Utility\Argument\ArrayUtility; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Card widget Twig extension. |
21
|
|
|
* |
22
|
|
|
* @author webeweb <https://github.com/webeweb/> |
23
|
|
|
* @package WBW\Bundle\AdminBSBBundle\Twig\Extension\Widget |
24
|
|
|
*/ |
25
|
|
|
class CardWidgetTwigExtension extends AbstractWidgetTwigExtension { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Service name. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
const SERVICE_NAME = "webeweb.bundle.adminbsbbundle.twig.extension.widget.card"; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Constructor. |
36
|
|
|
*/ |
37
|
|
|
public function __construct() { |
38
|
|
|
parent::__construct(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Displays an AdminBSB card header. |
43
|
|
|
* |
44
|
|
|
* @param array $args The arguments. |
45
|
|
|
* @return string Returns the AdminBSB card header. |
46
|
|
|
*/ |
47
|
|
|
public function adminBSBCardHeaderFunction(array $args = []) { |
48
|
|
|
|
49
|
|
|
// Initialize the paramters. |
50
|
|
|
$content = ArrayUtility::get($args, "content", ""); |
51
|
|
|
$description = ArrayUtility::get($args, "description"); |
52
|
|
|
$icon = ArrayUtility::get($args, "icon"); |
53
|
|
|
|
54
|
|
|
if (null !== $description) { |
55
|
|
|
$content .= "<small>" . $description . "</small>"; |
56
|
|
|
} |
57
|
|
|
if (null !== $icon) { |
58
|
|
|
$content = (new IconUITwigExtension())->adminBSBBasicIconFunction(["name" => $icon, "style" => "margin: -4px 0; vertical-align: sub;"]) . $content; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// Return the HTML. |
62
|
|
|
return (new HeadingTypographyTwigExtension())->bootstrapHeading2Function(["class" => "card-header", "content" => $content]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the Twig functions. |
67
|
|
|
* |
68
|
|
|
* @return array Returns the Twig functions. |
69
|
|
|
*/ |
70
|
|
|
public function getFunctions() { |
71
|
|
|
return [ |
72
|
|
|
new Twig_SimpleFunction("adminBSBCardHeader", [$this, "adminBSBCardHeaderFunction"], ["is_safe" => ["html"]]), |
73
|
|
|
]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|