|
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\BootstrapBundle\Twig\Extension; |
|
13
|
|
|
|
|
14
|
|
|
use Twig_Extension; |
|
15
|
|
|
use WBW\Bundle\BootstrapBundle\Navigation\NavigationInterface; |
|
16
|
|
|
use WBW\Library\Core\Utility\Argument\StringUtility; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Abstract Bootstrap Twig extension. |
|
20
|
|
|
* |
|
21
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
22
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension |
|
23
|
|
|
* @abstract |
|
24
|
|
|
*/ |
|
25
|
|
|
abstract class AbstractBootstrapTwigExtension 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 Bootstrap 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 bootstrapHTMLElement($element, $content, array $attrs = []) { |
|
57
|
|
|
|
|
58
|
|
|
// Initialize the templates. |
|
59
|
|
|
$template = "<%element%%attributes%>%innerHTML%</%element%>"; |
|
60
|
|
|
|
|
61
|
|
|
// Initialize the attributes. |
|
62
|
|
|
$attributes = trim(StringUtility::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 StringUtility::replace($template, ["%element%", "%attributes%", "%innerHTML%"], [trim($element), $attributes, $innerHTML]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|