diff --git a/system/docs/CHANGELOG.md b/system/docs/CHANGELOG.md index de00b8e169..243363d0e6 100644 --- a/system/docs/CHANGELOG.md +++ b/system/docs/CHANGELOG.md @@ -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). diff --git a/system/modules/core/library/Contao/Controller.php b/system/modules/core/library/Contao/Controller.php index 6547c4827a..33f7c1ff82 100644 --- a/system/modules/core/library/Contao/Controller.php +++ b/system/modules/core/library/Contao/Controller.php @@ -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; @@ -203,7 +203,18 @@ protected function getFrontendModule($intId, $strColumn='main') return '

' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], $strArticle) . '

'; } - 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); } } @@ -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; diff --git a/system/modules/core/modules/ModuleArticle.php b/system/modules/core/modules/ModuleArticle.php index 6cbc9972a4..e9643df7c7 100644 --- a/system/modules/core/modules/ModuleArticle.php +++ b/system/modules/core/modules/ModuleArticle.php @@ -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; } }