... | ... |
@@ -9,7 +9,6 @@ use Contao\Controller; |
9 | 9 |
use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController; |
10 | 10 |
use Contao\CoreBundle\DependencyInjection\Attribute\AsContentElement; |
11 | 11 |
use Contao\CoreBundle\Twig\FragmentTemplate; |
12 |
-use Contao\FilesModel; |
|
13 | 12 |
use Contao\System; |
14 | 13 |
use Symfony\Component\HttpFoundation\Request; |
15 | 14 |
use Symfony\Component\HttpFoundation\Response; |
... | ... |
@@ -32,31 +31,31 @@ class GridPlacementWrapperController extends AbstractContentElementController |
32 | 31 |
// Sicherstellen, dass alle notwendigen Felder vorhanden sind |
33 | 32 |
// Desktop Grid |
34 | 33 |
$arrGridCells = $model->vr_gpw_grid ? json_decode($model->vr_gpw_grid) : []; |
35 |
- $intCellStart = !empty($arrGridCells) ? min($arrGridCells) : $intDesktopColCount; |
|
36 |
- $intCellEnd = !empty($arrGridCells) ? max($arrGridCells) : $intDesktopColCount; |
|
34 |
+ $intCellStart = !empty($arrGridCells) && is_array($arrGridCells) ? min($arrGridCells) : 1; |
|
35 |
+ $intCellEnd = !empty($arrGridCells) && is_array($arrGridCells) ? max($arrGridCells) : $intDesktopColCount; |
|
37 | 36 |
|
38 | 37 |
// Tablet Grid |
39 | 38 |
$arrTabletGridCells = $model->vr_gpw_tablet_grid ? json_decode($model->vr_gpw_tablet_grid) : []; |
40 |
- $intTabletCellStart = !empty($arrTabletGridCells) ? min($arrTabletGridCells) : $intTabletColCount; |
|
41 |
- $intTabletCellEnd = !empty($arrTabletGridCells) ? max($arrTabletGridCells) : $intTabletColCount; |
|
39 |
+ $intTabletCellStart = !empty($arrTabletGridCells) && is_array($arrTabletGridCells) ? min($arrTabletGridCells) : 1; |
|
40 |
+ $intTabletCellEnd = !empty($arrTabletGridCells) && is_array($arrTabletGridCells) ? max($arrTabletGridCells) : $intTabletColCount; |
|
42 | 41 |
|
43 | 42 |
// Mobile Grid |
44 | 43 |
$arrMobileGridCells = $model->vr_gpw_mobile_grid ? json_decode($model->vr_gpw_mobile_grid) : []; |
45 |
- $intMobileCellStart = !empty($arrMobileGridCells) ? min($arrMobileGridCells) : $intMobileColCount; |
|
46 |
- $intMobileCellEnd = !empty($arrMobileGridCells) ? max($arrMobileGridCells) : $intMobileColCount; |
|
44 |
+ $intMobileCellStart = !empty($arrMobileGridCells) && is_array($arrMobileGridCells) ? min($arrMobileGridCells) : 1; |
|
45 |
+ $intMobileCellEnd = !empty($arrMobileGridCells) && is_array($arrMobileGridCells) ? max($arrMobileGridCells) : $intMobileColCount; |
|
47 | 46 |
|
48 | 47 |
|
49 | 48 |
// Vorbereiten der Daten, inklusive der neuen Tablet- und Mobile-Klassen |
50 | 49 |
$arrData = array_merge($template->getData(), [ |
51 |
- 'colStart' => $this->getColumnNumber(12, $intCellStart), |
|
52 |
- 'colEnd' => $this->getColumnNumber(12, $intCellEnd), |
|
53 |
- 'rowStart' => $this->getRowNumber(12, $intCellStart), |
|
54 |
- 'rowEnd' => $this->getRowNumber(12, $intCellEnd), |
|
55 |
- 'grid_classes' => $this->getGridClasses(12, $intCellStart, $intCellEnd), // Desktop-Klassen |
|
50 |
+ 'colStart' => $this->getColumnNumber($intDesktopColCount, $intCellStart), |
|
51 |
+ 'colEnd' => $this->getColumnNumber($intDesktopColCount, $intCellEnd), |
|
52 |
+ 'rowStart' => $this->getRowNumber($intDesktopColCount, $intCellStart), |
|
53 |
+ 'rowEnd' => $this->getRowNumber($intDesktopColCount, $intCellEnd), |
|
54 |
+ 'grid_classes' => $this->getGridClasses($intDesktopColCount, $intCellStart, $intCellEnd), // Desktop-Klassen |
|
56 | 55 |
|
57 | 56 |
// Spezifische Grid-Klassen für Tablet und Mobile |
58 |
- 'grid_tablet_classes' => count($arrTabletGridCells) ? $this->getGridClasses(12, $intTabletCellStart, $intTabletCellEnd, 'tablet') : '', |
|
59 |
- 'grid_mobile_classes' => count($arrMobileGridCells) ? $this->getGridClasses(12, $intMobileCellStart, $intMobileCellEnd, 'mobil') : '', |
|
57 |
+ 'grid_tablet_classes' => count($arrTabletGridCells) ? $this->getGridClasses($intTabletColCount, $intTabletCellStart, $intTabletCellEnd, 'tablet') : '', |
|
58 |
+ 'grid_mobile_classes' => count($arrMobileGridCells) ? $this->getGridClasses($intMobileColCount, $intMobileCellStart, $intMobileCellEnd, 'mobil') : '', |
|
60 | 59 |
]); |
61 | 60 |
|
62 | 61 |
$template->setData($arrData); |
... | ... |
@@ -5,6 +5,7 @@ declare(strict_types=1); |
5 | 5 |
namespace vonRotenberg\CoretoolsBundle\Controller\ContentElement; |
6 | 6 |
|
7 | 7 |
use Contao\ContentModel; |
8 |
+use Contao\Controller; |
|
8 | 9 |
use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController; |
9 | 10 |
use Contao\CoreBundle\DependencyInjection\Attribute\AsContentElement; |
10 | 11 |
use Contao\CoreBundle\Twig\FragmentTemplate; |
... | ... |
@@ -18,6 +19,11 @@ class GridPlacementWrapperController extends AbstractContentElementController |
18 | 19 |
{ |
19 | 20 |
protected function getResponse(FragmentTemplate $template, ContentModel $model, Request $request): Response |
20 | 21 |
{ |
22 |
+ Controller::loadDataContainer($model->getTable()); |
|
23 |
+ $intDesktopColCount = $GLOBALS['TL_DCA'][$model->getTable()]['fields']['vr_gpw_grid']['eval']['cols'] ?? 12; |
|
24 |
+ $intTabletColCount = $GLOBALS['TL_DCA'][$model->getTable()]['fields']['vr_gpw_tablet_grid']['eval']['cols'] ?? 12; |
|
25 |
+ $intMobileColCount = $GLOBALS['TL_DCA'][$model->getTable()]['fields']['vr_gpw_mobile_grid']['eval']['cols'] ?? 12; |
|
26 |
+ |
|
21 | 27 |
if (System::getContainer()->get('contao.routing.scope_matcher')->isFrontendRequest($request)) |
22 | 28 |
{ |
23 | 29 |
$GLOBALS['TL_CSS'][] = 'bundles/vonrotenbergcoretools/css/grid-placement-wrapper.min.css|static'; |
... | ... |
@@ -25,19 +31,19 @@ class GridPlacementWrapperController extends AbstractContentElementController |
25 | 31 |
|
26 | 32 |
// Sicherstellen, dass alle notwendigen Felder vorhanden sind |
27 | 33 |
// Desktop Grid |
28 |
- $gridCells = $model->vr_gpw_grid ? json_decode($model->vr_gpw_grid) : []; |
|
29 |
- $intCellStart = !empty($gridCells) ? min($gridCells) : 12; |
|
30 |
- $intCellEnd = !empty($gridCells) ? max($gridCells) : 12; |
|
34 |
+ $arrGridCells = $model->vr_gpw_grid ? json_decode($model->vr_gpw_grid) : []; |
|
35 |
+ $intCellStart = !empty($arrGridCells) ? min($arrGridCells) : $intDesktopColCount; |
|
36 |
+ $intCellEnd = !empty($arrGridCells) ? max($arrGridCells) : $intDesktopColCount; |
|
31 | 37 |
|
32 | 38 |
// Tablet Grid |
33 |
- $tabletGridCells = $model->vr_gpw_tablet_grid ? json_decode($model->vr_gpw_tablet_grid) : []; |
|
34 |
- $tabletCellStart = !empty($tabletGridCells) ? min($tabletGridCells) : 12; |
|
35 |
- $tabletCellEnd = !empty($tabletGridCells) ? max($tabletGridCells) : 12; |
|
39 |
+ $arrTabletGridCells = $model->vr_gpw_tablet_grid ? json_decode($model->vr_gpw_tablet_grid) : []; |
|
40 |
+ $intTabletCellStart = !empty($arrTabletGridCells) ? min($arrTabletGridCells) : $intTabletColCount; |
|
41 |
+ $intTabletCellEnd = !empty($arrTabletGridCells) ? max($arrTabletGridCells) : $intTabletColCount; |
|
36 | 42 |
|
37 | 43 |
// Mobile Grid |
38 |
- $mobileGridCells = $model->vr_gpw_mobile_grid ? json_decode($model->vr_gpw_mobile_grid) : []; |
|
39 |
- $mobileCellStart = !empty($mobileGridCells) ? min($mobileGridCells) : 12; |
|
40 |
- $mobileCellEnd = !empty($mobileGridCells) ? max($mobileGridCells) : 12; |
|
44 |
+ $arrMobileGridCells = $model->vr_gpw_mobile_grid ? json_decode($model->vr_gpw_mobile_grid) : []; |
|
45 |
+ $intMobileCellStart = !empty($arrMobileGridCells) ? min($arrMobileGridCells) : $intMobileColCount; |
|
46 |
+ $intMobileCellEnd = !empty($arrMobileGridCells) ? max($arrMobileGridCells) : $intMobileColCount; |
|
41 | 47 |
|
42 | 48 |
|
43 | 49 |
// Vorbereiten der Daten, inklusive der neuen Tablet- und Mobile-Klassen |
... | ... |
@@ -49,8 +55,8 @@ class GridPlacementWrapperController extends AbstractContentElementController |
49 | 55 |
'grid_classes' => $this->getGridClasses(12, $intCellStart, $intCellEnd), // Desktop-Klassen |
50 | 56 |
|
51 | 57 |
// Spezifische Grid-Klassen für Tablet und Mobile |
52 |
- 'grid_tablet_classes' => count($tabletGridCells) ? $this->getGridClasses(12, $tabletCellStart, $tabletCellEnd, 'tablet') : '', |
|
53 |
- 'grid_mobile_classes' => count($mobileGridCells) ? $this->getGridClasses(12, $mobileCellStart, $mobileCellEnd, 'mobil') : '', |
|
58 |
+ 'grid_tablet_classes' => count($arrTabletGridCells) ? $this->getGridClasses(12, $intTabletCellStart, $intTabletCellEnd, 'tablet') : '', |
|
59 |
+ 'grid_mobile_classes' => count($arrMobileGridCells) ? $this->getGridClasses(12, $intMobileCellStart, $intMobileCellEnd, 'mobil') : '', |
|
54 | 60 |
]); |
55 | 61 |
|
56 | 62 |
$template->setData($arrData); |
... | ... |
@@ -18,7 +18,90 @@ class GridPlacementWrapperController extends AbstractContentElementController |
18 | 18 |
{ |
19 | 19 |
protected function getResponse(FragmentTemplate $template, ContentModel $model, Request $request): Response |
20 | 20 |
{ |
21 |
+ if (System::getContainer()->get('contao.routing.scope_matcher')->isFrontendRequest($request)) |
|
22 |
+ { |
|
23 |
+ $GLOBALS['TL_CSS'][] = 'bundles/vonrotenbergcoretools/css/grid-placement-wrapper.min.css|static'; |
|
24 |
+ } |
|
21 | 25 |
|
26 |
+ // Sicherstellen, dass alle notwendigen Felder vorhanden sind |
|
27 |
+ // Desktop Grid |
|
28 |
+ $gridCells = $model->vr_gpw_grid ? json_decode($model->vr_gpw_grid) : []; |
|
29 |
+ $intCellStart = !empty($gridCells) ? min($gridCells) : 12; |
|
30 |
+ $intCellEnd = !empty($gridCells) ? max($gridCells) : 12; |
|
31 |
+ |
|
32 |
+ // Tablet Grid |
|
33 |
+ $tabletGridCells = $model->vr_gpw_tablet_grid ? json_decode($model->vr_gpw_tablet_grid) : []; |
|
34 |
+ $tabletCellStart = !empty($tabletGridCells) ? min($tabletGridCells) : 12; |
|
35 |
+ $tabletCellEnd = !empty($tabletGridCells) ? max($tabletGridCells) : 12; |
|
36 |
+ |
|
37 |
+ // Mobile Grid |
|
38 |
+ $mobileGridCells = $model->vr_gpw_mobile_grid ? json_decode($model->vr_gpw_mobile_grid) : []; |
|
39 |
+ $mobileCellStart = !empty($mobileGridCells) ? min($mobileGridCells) : 12; |
|
40 |
+ $mobileCellEnd = !empty($mobileGridCells) ? max($mobileGridCells) : 12; |
|
41 |
+ |
|
42 |
+ |
|
43 |
+ // Vorbereiten der Daten, inklusive der neuen Tablet- und Mobile-Klassen |
|
44 |
+ $arrData = array_merge($template->getData(), [ |
|
45 |
+ 'colStart' => $this->getColumnNumber(12, $intCellStart), |
|
46 |
+ 'colEnd' => $this->getColumnNumber(12, $intCellEnd), |
|
47 |
+ 'rowStart' => $this->getRowNumber(12, $intCellStart), |
|
48 |
+ 'rowEnd' => $this->getRowNumber(12, $intCellEnd), |
|
49 |
+ 'grid_classes' => $this->getGridClasses(12, $intCellStart, $intCellEnd), // Desktop-Klassen |
|
50 |
+ |
|
51 |
+ // Spezifische Grid-Klassen für Tablet und Mobile |
|
52 |
+ 'grid_tablet_classes' => count($tabletGridCells) ? $this->getGridClasses(12, $tabletCellStart, $tabletCellEnd, 'tablet') : '', |
|
53 |
+ 'grid_mobile_classes' => count($mobileGridCells) ? $this->getGridClasses(12, $mobileCellStart, $mobileCellEnd, 'mobil') : '', |
|
54 |
+ ]); |
|
55 |
+ |
|
56 |
+ $template->setData($arrData); |
|
22 | 57 |
return $template->getResponse(); |
23 | 58 |
} |
59 |
+ |
|
60 |
+ |
|
61 |
+ private function getColumnNumber(int $columns, int $cellIndex): int |
|
62 |
+ { |
|
63 |
+ if ($columns <= 0) |
|
64 |
+ { |
|
65 |
+ throw new \InvalidArgumentException('The number of columns must be greater than zero.'); |
|
66 |
+ } |
|
67 |
+ |
|
68 |
+ return ($cellIndex % $columns) + 1; |
|
69 |
+ } |
|
70 |
+ |
|
71 |
+ |
|
72 |
+ private function getRowNumber(int $columns, int $cellIndex): int |
|
73 |
+ { |
|
74 |
+ if ($columns <= 0) |
|
75 |
+ { |
|
76 |
+ throw new \InvalidArgumentException('The number of columns must be greater than zero.'); |
|
77 |
+ } |
|
78 |
+ |
|
79 |
+ return intdiv($cellIndex, $columns) + 1; |
|
80 |
+ } |
|
81 |
+ |
|
82 |
+ private function getGridClasses(int $columns, int $intCellStart, int $intCellEnd, string $strViewportName = ''): string |
|
83 |
+ { |
|
84 |
+ // Berechnung der Start-/Endspalten |
|
85 |
+ $colStart = $this->getColumnNumber($columns, $intCellStart); |
|
86 |
+ $colEnd = $this->getColumnNumber($columns, $intCellEnd); |
|
87 |
+ |
|
88 |
+ // Berechnung der Start-/Endreihen |
|
89 |
+ $rowStart = $this->getRowNumber($columns, $intCellStart); |
|
90 |
+ $rowEnd = $this->getRowNumber($columns, $intCellEnd); |
|
91 |
+ |
|
92 |
+ // Generierung der CSS-Klassennamen |
|
93 |
+ if (!empty($strViewportName)) |
|
94 |
+ { |
|
95 |
+ $strViewportName = '-' . $strViewportName; |
|
96 |
+ } |
|
97 |
+ $cssClasses = [ |
|
98 |
+ "gp--col$strViewportName-start-$colStart", |
|
99 |
+ "gp--col$strViewportName-end-" . ($colEnd + 1), // col-end benötigt +1 gemäß Ihrer CSS-Definition |
|
100 |
+ "gp--row$strViewportName-start-$rowStart", |
|
101 |
+ "gp--row$strViewportName-end-" . ($rowEnd + 1), // row-end benötigt ebenfalls +1 |
|
102 |
+ ]; |
|
103 |
+ |
|
104 |
+ // Klassennamen als String trennen |
|
105 |
+ return implode(' ', $cssClasses); |
|
106 |
+ } |
|
24 | 107 |
} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,24 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+declare(strict_types=1); |
|
4 |
+ |
|
5 |
+namespace vonRotenberg\CoretoolsBundle\Controller\ContentElement; |
|
6 |
+ |
|
7 |
+use Contao\ContentModel; |
|
8 |
+use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController; |
|
9 |
+use Contao\CoreBundle\DependencyInjection\Attribute\AsContentElement; |
|
10 |
+use Contao\CoreBundle\Twig\FragmentTemplate; |
|
11 |
+use Contao\FilesModel; |
|
12 |
+use Contao\System; |
|
13 |
+use Symfony\Component\HttpFoundation\Request; |
|
14 |
+use Symfony\Component\HttpFoundation\Response; |
|
15 |
+ |
|
16 |
+#[AsContentElement(category: 'miscellaneous', nestedFragments: true)] |
|
17 |
+class GridPlacementWrapperController extends AbstractContentElementController |
|
18 |
+{ |
|
19 |
+ protected function getResponse(FragmentTemplate $template, ContentModel $model, Request $request): Response |
|
20 |
+ { |
|
21 |
+ |
|
22 |
+ return $template->getResponse(); |
|
23 |
+ } |
|
24 |
+} |