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