Browse code

Use correct fallbacks for grid

Benjamin Roth authored on24/04/2025 10:22:48
Showing1 changed files
... ...
@@ -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);