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\Grid; |
13
|
|
|
|
14
|
|
|
use Twig_SimpleFunction; |
15
|
|
|
use WBW\Library\Core\Utility\Argument\ArrayUtility; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Grid Twig extension. |
19
|
|
|
* |
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
21
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\Grid |
22
|
|
|
*/ |
23
|
|
|
class GridTwigExtension extends AbstractGridTwigExtension { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Service name. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
const SERVICE_NAME = "webeweb.bundle.bootstrapbundle.twig.extension.grid.grid"; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Constructor. |
34
|
|
|
*/ |
35
|
|
|
public function __construct() { |
36
|
|
|
parent::__construct(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Displays a Bootstrap grid. |
41
|
|
|
* |
42
|
|
|
* @param array $args The arguments. |
43
|
|
|
* @return string Returns the Bootstrap grid. |
44
|
|
|
*/ |
45
|
|
|
public function bootstrapGridFunction(array $args = []) { |
46
|
|
|
|
47
|
|
|
// Initialize the output. |
48
|
|
|
$output = []; |
49
|
|
|
|
50
|
|
|
$output[] = $this->bootstrapGridStackedFunction($args); |
51
|
|
|
$output[] = $this->bootstrapGridOffsetFunction($args); |
52
|
|
|
$output[] = $this->bootstrapGridPushFunction($args); |
53
|
|
|
$output[] = $this->bootstrapGridPullFunction($args); |
54
|
|
|
|
55
|
|
|
// Return the output. |
56
|
|
|
return trim(implode(" ", $output)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Displays a Bootstrap grid with offset. |
61
|
|
|
* |
62
|
|
|
* @param array $args The arguments. |
63
|
|
|
* @return string Returns the Bootstrap grid with offset. |
64
|
|
|
*/ |
65
|
|
|
public function bootstrapGridOffsetFunction(array $args = []) { |
66
|
|
|
return $this->bootstrapGrid(ArrayUtility::get($args, "lgOffset"), ArrayUtility::get($args, "mdOffset"), ArrayUtility::get($args, "smOffset"), ArrayUtility::get($args, "xsOffset"), ArrayUtility::get($args, "recopyOffset", false), "offset-"); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Displays a Bootstrap grid with pull. |
71
|
|
|
* |
72
|
|
|
* @param array $args The arguments. |
73
|
|
|
* @return string Returns the Bootstrap grid with pull. |
74
|
|
|
*/ |
75
|
|
|
public function bootstrapGridPullFunction(array $args = []) { |
76
|
|
|
return $this->bootstrapGrid(ArrayUtility::get($args, "lgPull"), ArrayUtility::get($args, "mdPull"), ArrayUtility::get($args, "smPull"), ArrayUtility::get($args, "xsPull"), ArrayUtility::get($args, "recopyPull", false), "pull-"); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Displays a Bootstrap grid with push. |
81
|
|
|
* |
82
|
|
|
* @param array $args The arguments. |
83
|
|
|
* @return string Returns the Bootstrap grid with push. |
84
|
|
|
*/ |
85
|
|
|
public function bootstrapGridPushFunction(array $args = []) { |
86
|
|
|
return $this->bootstrapGrid(ArrayUtility::get($args, "lgPush"), ArrayUtility::get($args, "mdPush"), ArrayUtility::get($args, "smPush"), ArrayUtility::get($args, "xsPush"), ArrayUtility::get($args, "recopyPush", false), "push-"); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Displays a Bootstrap grid with stacked-to-horizontal. |
91
|
|
|
* |
92
|
|
|
* @param array $args The arguments. |
93
|
|
|
* @return string Returns the Bootstrap grid with stacked-to-horizontal. |
94
|
|
|
*/ |
95
|
|
|
public function bootstrapGridStackedFunction(array $args = []) { |
96
|
|
|
return $this->bootstrapGrid(ArrayUtility::get($args, "lg"), ArrayUtility::get($args, "md"), ArrayUtility::get($args, "sm"), ArrayUtility::get($args, "xs"), ArrayUtility::get($args, "recopy", false), ""); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get the Twig functions. |
101
|
|
|
* |
102
|
|
|
* @return array Returns the Twig functions. |
103
|
|
|
*/ |
104
|
|
|
public function getFunctions() { |
105
|
|
|
return [ |
106
|
|
|
new Twig_SimpleFunction("bootstrapGrid", [$this, "bootstrapGridFunction"], ["is_safe" => ["html"]]), |
107
|
|
|
new Twig_SimpleFunction("bootstrapGridOffset", [$this, "bootstrapGridOffsetFunction"], ["is_safe" => ["html"]]), |
108
|
|
|
new Twig_SimpleFunction("bootstrapGridPull", [$this, "bootstrapGridPullFunction"], ["is_safe" => ["html"]]), |
109
|
|
|
new Twig_SimpleFunction("bootstrapGridPush", [$this, "bootstrapGridPushFunction"], ["is_safe" => ["html"]]), |
110
|
|
|
new Twig_SimpleFunction("bootstrapGridStacked", [$this, "bootstrapGridStackedFunction"], ["is_safe" => ["html"]]), |
111
|
|
|
]; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
} |
115
|
|
|
|