1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the bootstrap-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\CoreBundle\Twig\Extension; |
13
|
|
|
|
14
|
|
|
use Twig_Extension; |
15
|
|
|
use WBW\Bundle\CoreBundle\Navigation\NavigationInterface; |
16
|
|
|
use WBW\Library\Core\Argument\StringHelper; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Abstract Core Twig extension. |
20
|
|
|
* |
21
|
|
|
* @author webeweb <https://github.com/webeweb/> |
22
|
|
|
* @package WBW\Bundle\CoreBundle\Twig\Extension |
23
|
|
|
* @abstract |
24
|
|
|
*/ |
25
|
|
|
abstract class AbstractCoreTwigExtension extends Twig_Extension { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Default content. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
const DEFAULT_CONTENT = " "; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Default href. |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
const DEFAULT_HREF = NavigationInterface::NAVIGATION_HREF_DEFAULT; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Constructor. |
43
|
|
|
*/ |
44
|
|
|
protected function __construct() { |
45
|
|
|
// NOTHING TO DO. |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Displays a Core HTML element. |
50
|
|
|
* |
51
|
|
|
* @param string $element The object. |
52
|
|
|
* @param string $content The content. |
53
|
|
|
* @param array $attrs The attributes. |
54
|
|
|
* @return string Returns the Bootstrap HTML element. |
55
|
|
|
*/ |
56
|
|
|
public static function coreHTMLElement($element, $content, array $attrs = []) { |
57
|
|
|
|
58
|
|
|
// Initialize the templates. |
59
|
|
|
$template = "<%element%%attributes%>%innerHTML%</%element%>"; |
60
|
|
|
|
61
|
|
|
// Initialize the attributes. |
62
|
|
|
$attributes = trim(StringHelper::parseArray($attrs)); |
63
|
|
|
if (0 < strlen($attributes)) { |
64
|
|
|
$attributes = " " . $attributes; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
// Initialize the parameters. |
68
|
|
|
$innerHTML = null !== $content ? trim($content, " ") : ""; |
69
|
|
|
|
70
|
|
|
// Return the HTML. |
71
|
|
|
return StringHelper::replace($template, ["%element%", "%attributes%", "%innerHTML%"], [trim($element), $attributes, $innerHTML]); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|