|
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\Environment; |
|
15
|
|
|
use WBW\Bundle\AdminBSBBundle\Twig\Extension\AbstractTwigExtension; |
|
16
|
|
|
use WBW\Bundle\AdminBSBBundle\Twig\Extension\RendererTwigExtension; |
|
17
|
|
|
use WBW\Bundle\AdminBSBBundle\Twig\Extension\Typography\TypographyTwigExtension; |
|
18
|
|
|
use WBW\Bundle\AdminBSBBundle\Twig\Extension\Typography\TypographyTwigExtensionTrait; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Abstract card twig extension. |
|
22
|
|
|
* |
|
23
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
24
|
|
|
* @package WBW\Bundle\AdminBSBBundle\Twig\Extension\Widget |
|
25
|
|
|
* @abstract |
|
26
|
|
|
*/ |
|
27
|
|
|
abstract class AbstractCardTwigExtension extends AbstractTwigExtension { |
|
28
|
|
|
|
|
29
|
|
|
use TypographyTwigExtensionTrait; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Constructor. |
|
33
|
|
|
* |
|
34
|
|
|
* @param Environment $twigEnvironment The Twig environment. |
|
35
|
|
|
* @param TypographyTwigExtension $typographyTwigExtension The Typography Twig extension. |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(Environment $twigEnvironment, TypographyTwigExtension $typographyTwigExtension) { |
|
38
|
|
|
parent::__construct($twigEnvironment); |
|
39
|
|
|
$this->setTypographyTwigExtension($typographyTwigExtension); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Displays an AdminBSB card header. |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $content The content. |
|
46
|
|
|
* @param string|null $description The description. |
|
47
|
|
|
* @param string|null $icon The icon. |
|
48
|
|
|
* @return string Returns the AdminBSB card header. |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function adminBSBCardHeader(string $content, ?string $description, ?string $icon): string { |
|
51
|
|
|
|
|
52
|
|
|
$innerHTML = $content; |
|
53
|
|
|
if (null !== $description) { |
|
54
|
|
|
$innerHTML .= static::coreHTMLElement("small", $description); |
|
55
|
|
|
} |
|
56
|
|
|
if (null !== $icon) { |
|
57
|
|
|
$innerHTML = RendererTwigExtension::renderIcon($this->getTwigEnvironment(), $icon, "margin: -4px 4px 0 0; vertical-align: sub;") . $innerHTML; |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $this->getTypographyTwigExtension()->bootstrapHeading2Function(["class" => "card-header", "content" => $innerHTML]); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
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: