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\CSS; |
13
|
|
|
|
14
|
|
|
use Twig_Environment; |
15
|
|
|
use WBW\Bundle\BootstrapBundle\Helper\GridHelper; |
16
|
|
|
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractTwigExtension; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Abstract grid Twig extension. |
20
|
|
|
* |
21
|
|
|
* @author webeweb <https://github.com/webeweb/> |
22
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\CSS |
23
|
|
|
* @abstract |
24
|
|
|
*/ |
25
|
|
|
abstract class AbstractGridTwigExtension extends AbstractTwigExtension { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Constructor. |
29
|
|
|
* |
30
|
|
|
* @param Twig_Environment $twigEnvironment The Twig environment. |
31
|
|
|
*/ |
32
|
|
|
protected function __construct(Twig_Environment $twigEnvironment) { |
33
|
|
|
parent::__construct($twigEnvironment); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Displays a Bootstrap grid. |
38
|
|
|
* |
39
|
|
|
* @param string $lg The large column size. |
40
|
|
|
* @param string $md The medium column size. |
41
|
|
|
* @param string $sm The small column size. |
42
|
|
|
* @param string $xs The extra-small column size. |
43
|
|
|
* @param string $recopy Recopy ? |
44
|
|
|
* @param string $prefix The column prefix. |
45
|
|
|
* @return string Returns the Bootstrap grid. |
46
|
|
|
*/ |
47
|
|
|
protected function bootstrapGrid($lg, $md, $sm, $xs, $recopy, $prefix) { |
48
|
|
|
|
49
|
|
|
// Initialize the values. |
50
|
|
|
$found = null; |
51
|
|
|
$values = [&$lg, &$md, &$sm, &$xs]; |
52
|
|
|
|
53
|
|
|
// Handle each value. |
54
|
|
|
foreach ($values as &$current) { |
55
|
|
|
if (1 <= $current && $current <= 12) { |
56
|
|
|
$found = $current; |
57
|
|
|
} |
58
|
|
|
if (null === $current && true === $recopy && null !== $found) { |
59
|
|
|
$current = $found; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// Initialize the columns. |
64
|
|
|
$columns = []; |
65
|
|
|
|
66
|
|
|
$columns[] = GridHelper::getCSSClassname("lg", $lg, $prefix, 1, 12); |
67
|
|
|
$columns[] = GridHelper::getCSSClassname("md", $md, $prefix, 1, 12);; |
68
|
|
|
$columns[] = GridHelper::getCSSClassname("sm", $sm, $prefix, 1, 12);; |
69
|
|
|
$columns[] = GridHelper::getCSSClassname("xs", $xs, $prefix, 1, 12);; |
70
|
|
|
|
71
|
|
|
// Return the columns. |
72
|
|
|
return trim(implode(" ", $columns)); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|