Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Add the CSS classes "first" and "last" to articles/content elements (…
Browse files Browse the repository at this point in the history
…see #2583)
  • Loading branch information
leofeyer committed Sep 26, 2013
1 parent e951b77 commit cb375c9
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 5 deletions.
3 changes: 3 additions & 0 deletions system/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Contao Open Source CMS Changelog
Version 3.2.beta1 (2013-XX-XX)
------------------------------

### New
Add the CSS classes "first" and "last" to articles/content elements (see #2583).

### New
The form generator now supports defining a minimum input length (see #4394).

Expand Down
59 changes: 55 additions & 4 deletions system/modules/core/library/Contao/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ protected function getFrontendModule($intId, $strColumn='main')

if ($strSection == $strColumn)
{
$strBuffer = $this->getArticle($strArticle);
$objArticle = \ArticleModel::findByIdOrAliasAndPid($strArticle, $objPage->id);

// Send a 404 header if the article does not exist
if ($strBuffer === false)
if ($objArticle === null)
{
// Do not index the page
$objPage->noSearch = 1;
Expand All @@ -203,7 +203,18 @@ protected function getFrontendModule($intId, $strColumn='main')
return '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], $strArticle) . '</p>';
}

return $strBuffer;
// Add the "first" and "last" classes (see #2583)
$arrCss = deserialize($objArticle->cssID);

if (!is_array($arrCss))
{
$arrCss = array('', '');
}

$arrCss[1] .= 'first last';
$objArticle->cssID = serialize($arrCss);

return $this->getArticle($objArticle);
}
}

Expand All @@ -222,11 +233,51 @@ protected function getFrontendModule($intId, $strColumn='main')
}

$return = '';
$intCount = 0;
$blnMultiMode = ($objArticles->count() > 1);
$intLast = $objArticles->count() - 1;

while ($objArticles->next())
{
$return .= $this->getArticle($objArticles->current(), $blnMultiMode, false, $strColumn);
$objRow = $objArticles->current();

// Add the "first" and "last" classes (see #2583)
if ($intCount == 0 || $intCount == $intLast)
{
$arrCss = deserialize($objRow->cssID);
$arrTeaserCss = deserialize($objRow->teaserCssID);

if (!is_array($arrCss))
{
$arrCss = array('', '');
}

if (!is_array($arrTeaserCss))
{
$arrTeaserCss = array('', '');
}

if ($intCount == 0)
{
$arrCss[1] .= ' first';
$arrTeaserCss[1] .= ' first';
}

if ($intCount == $intLast)
{
$arrCss[1] .= ' last';
$arrTeaserCss[1] .= ' last';
}

$arrCss[1] = trim($arrCss[1]);
$objRow->cssID = serialize($arrCss);

$arrTeaserCss[1] = trim($arrTeaserCss[1]);
$objRow->teaserCssID = serialize($arrTeaserCss);
}

$return .= $this->getArticle($objRow, $blnMultiMode, false, $strColumn);
++$intCount;
}

return $return;
Expand Down
27 changes: 26 additions & 1 deletion system/modules/core/modules/ModuleArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,34 @@ protected function compile()

if ($objCte !== null)
{
$intCount = 0;
$intLast = $objCte->count() - 1;

while ($objCte->next())
{
$arrElements[] = $this->getContentElement($objCte->current(), $this->strColumn);
$objRow = $objCte->current();

// Add the "first" and "last" classes (see #2583)
if ($intCount == 0 || $intCount == $intLast)
{
$arrCss = deserialize($objRow->cssID);

if ($intCount == 0)
{
$arrCss[1] .= ' first';
}

if ($intCount == $intLast)
{
$arrCss[1] .= ' last';
}

$arrCss[1] = trim($arrCss[1]);
$objRow->cssID = serialize($arrCss);
}

$arrElements[] = $this->getContentElement($objRow, $this->strColumn);
++$intCount;
}
}

Expand Down

0 comments on commit cb375c9

Please sign in to comment.