Skip to content

Commit

Permalink
Added support for nested wrappers, closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Nov 11, 2014
1 parent 4092f40 commit 4839989
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/MadeYourDay/Contao/Columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions src/MadeYourDay/Contao/Element/ColumnStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/MadeYourDay/Contao/Element/ColumnStop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 34 additions & 1 deletion src/MadeYourDay/Contao/Element/ColumnsStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= '<div class="' . implode(' ', $classes) . '">';

}

}

$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();
}

/**
Expand Down
15 changes: 14 additions & 1 deletion src/MadeYourDay/Contao/Element/ColumnsStop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= '</div>';
}
}

return parent::generate() . $htmlSuffix;
}

/**
Expand Down

0 comments on commit 4839989

Please sign in to comment.