From 4839989c4e8741dfee9546a77f34892fb92a6b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Auswo=CC=88ger?= Date: Tue, 11 Nov 2014 16:57:20 +0100 Subject: [PATCH] Added support for nested wrappers, closes #1 --- src/MadeYourDay/Contao/Columns.php | 14 +++++--- .../Contao/Element/ColumnStart.php | 4 +++ src/MadeYourDay/Contao/Element/ColumnStop.php | 4 +++ .../Contao/Element/ColumnsStart.php | 35 ++++++++++++++++++- .../Contao/Element/ColumnsStop.php | 15 +++++++- 5 files changed, 65 insertions(+), 7 deletions(-) diff --git a/src/MadeYourDay/Contao/Columns.php b/src/MadeYourDay/Contao/Columns.php index b67ab7e..ee35ef3 100644 --- a/src/MadeYourDay/Contao/Columns.php +++ b/src/MadeYourDay/Contao/Columns.php @@ -91,26 +91,30 @@ public function onsubmitCallback($dc) if ($activeRecord->type === 'rs_columns_start' || $activeRecord->type === 'rs_column_start') { - // Find the next start or stop element + // Find the next columns or column element $nextElement = \Database::getInstance() ->prepare(' SELECT type FROM tl_content WHERE pid = ? - AND type IN (?, ?) + AND type IN (\'rs_column_start\', \'rs_column_stop\', \'rs_columns_start\', \'rs_columns_stop\') AND sorting > ? ORDER BY sorting ASC LIMIT 1 ') ->execute( $activeRecord->pid, - $activeRecord->type, - substr($activeRecord->type, 0, -5) . 'stop', $activeRecord->sorting ); // Check if a stop element should be created - if (!$nextElement->type || substr($nextElement->type, -6) === '_start') { + if ( + !$nextElement->type + || ($activeRecord->type === 'rs_columns_start' && $nextElement->type === 'rs_column_stop') + || ($activeRecord->type === 'rs_column_start' && ( + $nextElement->type === 'rs_column_start' || $nextElement->type === 'rs_columns_stop' + )) + ) { \Database::getInstance() ->prepare('INSERT INTO tl_content %s') ->set(array( diff --git a/src/MadeYourDay/Contao/Element/ColumnStart.php b/src/MadeYourDay/Contao/Element/ColumnStart.php index dfd7871..9229b4c 100644 --- a/src/MadeYourDay/Contao/Element/ColumnStart.php +++ b/src/MadeYourDay/Contao/Element/ColumnStart.php @@ -27,6 +27,10 @@ class ColumnStart extends \ContentElement */ public function generate() { + if (TL_MODE === 'BE') { + return parent::generate(); + } + $parentKey = ($this->arrData['ptable'] ?: 'tl_article') . '__' . $this->arrData['pid']; if (isset($GLOBALS['TL_RS_COLUMNS'][$parentKey])) { $GLOBALS['TL_RS_COLUMNS'][$parentKey]['active'] = false; diff --git a/src/MadeYourDay/Contao/Element/ColumnStop.php b/src/MadeYourDay/Contao/Element/ColumnStop.php index 159b561..20aaf1f 100644 --- a/src/MadeYourDay/Contao/Element/ColumnStop.php +++ b/src/MadeYourDay/Contao/Element/ColumnStop.php @@ -27,6 +27,10 @@ class ColumnStop extends \ContentElement */ public function generate() { + if (TL_MODE === 'BE') { + return parent::generate(); + } + $parentKey = ($this->arrData['ptable'] ?: 'tl_article') . '__' . $this->arrData['pid']; if (isset($GLOBALS['TL_RS_COLUMNS'][$parentKey])) { $GLOBALS['TL_RS_COLUMNS'][$parentKey]['active'] = true; diff --git a/src/MadeYourDay/Contao/Element/ColumnsStart.php b/src/MadeYourDay/Contao/Element/ColumnsStart.php index 2f14d39..2e53599 100644 --- a/src/MadeYourDay/Contao/Element/ColumnsStart.php +++ b/src/MadeYourDay/Contao/Element/ColumnsStart.php @@ -27,14 +27,47 @@ class ColumnsStart extends \ContentElement */ public function generate() { + if (TL_MODE === 'BE') { + return parent::generate(); + } + $parentKey = ($this->arrData['ptable'] ?: 'tl_article') . '__' . $this->arrData['pid']; + + $htmlPrefix = ''; + + if (!empty($GLOBALS['TL_RS_COLUMNS'][$parentKey])) { + + if ($GLOBALS['TL_RS_COLUMNS'][$parentKey]['active']) { + + $GLOBALS['TL_RS_COLUMNS'][$parentKey]['count']++; + $count = $GLOBALS['TL_RS_COLUMNS'][$parentKey]['count']; + + if ($count) { + + $classes = array('rs-column'); + foreach ($GLOBALS['TL_RS_COLUMNS'][$parentKey]['config'] as $name => $media) { + $classes = array_merge($classes, $media[($count - 1) % count($media)]); + if ($count - 1 < count($media)) { + $classes[] = '-' . $name . '-first-row'; + } + } + + $htmlPrefix .= '
'; + + } + + } + + $GLOBALS['TL_RS_COLUMNS_STACK'][$parentKey][] = $GLOBALS['TL_RS_COLUMNS'][$parentKey]; + } + $GLOBALS['TL_RS_COLUMNS'][$parentKey] = array( 'active' => true, 'count' => 0, 'config' => static::getColumnsConfiguration($this->arrData), ); - return parent::generate(); + return $htmlPrefix . parent::generate(); } /** diff --git a/src/MadeYourDay/Contao/Element/ColumnsStop.php b/src/MadeYourDay/Contao/Element/ColumnsStop.php index c3437cb..23fc8e6 100644 --- a/src/MadeYourDay/Contao/Element/ColumnsStop.php +++ b/src/MadeYourDay/Contao/Element/ColumnsStop.php @@ -27,12 +27,25 @@ class ColumnsStop extends \ContentElement */ public function generate() { + if (TL_MODE === 'BE') { + return parent::generate(); + } + $parentKey = ($this->arrData['ptable'] ?: 'tl_article') . '__' . $this->arrData['pid']; if (isset($GLOBALS['TL_RS_COLUMNS'][$parentKey])) { unset($GLOBALS['TL_RS_COLUMNS'][$parentKey]); } - return parent::generate(); + $htmlSuffix = ''; + + if (!empty($GLOBALS['TL_RS_COLUMNS_STACK'][$parentKey])) { + $GLOBALS['TL_RS_COLUMNS'][$parentKey] = array_pop($GLOBALS['TL_RS_COLUMNS_STACK'][$parentKey]); + if ($GLOBALS['TL_RS_COLUMNS'][$parentKey]['active']) { + $htmlSuffix .= '
'; + } + } + + return parent::generate() . $htmlSuffix; } /**