From d08d013f73fed494b85f8b6dc959910e69cdc5df Mon Sep 17 00:00:00 2001 From: Stefan Galinski <stefan@sgalinski.de> Date: Mon, 18 Jul 2016 00:03:42 +0200 Subject: [PATCH] [FEATURE] Allow the rendering of the latest view via typoscript on category pages --- Classes/Controller/LatestController.php | 15 ++++----------- Classes/Domain/Repository/NewsRepository.php | 2 +- README.md | 13 ++++++++++++- .../Private/Templates/ListByCategory/Index.html | 10 +++++++++- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Classes/Controller/LatestController.php b/Classes/Controller/LatestController.php index 57860f8..1cd7fda 100644 --- a/Classes/Controller/LatestController.php +++ b/Classes/Controller/LatestController.php @@ -55,17 +55,13 @@ class LatestController extends AbstractController { $limit = ((int) $this->settings['limit']); $limit = ($limit < 1 ? 1 : $limit); - $filterByCategories = FALSE; - $categoryUids = GeneralUtility::intExplode(',', $this->settings['categories']); - foreach ($categoryUids as $categoryUid) { - if ($categoryUid > 0) { - $filterByCategories = TRUE; - break; - } + $categoryUids = GeneralUtility::intExplode(',', $this->settings['categories'], TRUE); + if (!count($categoryUids) && (int) $GLOBALS['TSFE']->page['doktype'] === 117) { + $categoryUids = [$GLOBALS['TSFE']->id]; } $latestNewsEntries = $this->newsRepository->findLastUpdatedOrHighlightedNewsByCategories( - $limit, FALSE, ($filterByCategories ? $categoryUids : NULL), 0, TRUE + $limit, FALSE, $categoryUids, 0, TRUE ); $newsMetaData = []; @@ -73,7 +69,6 @@ class LatestController extends AbstractController { foreach ($latestNewsEntries as $latestNewsEntry) { /** @var News $latestNewsEntry */ /** @var Category $category */ - $categoryUid = $latestNewsEntry->getPid(); $category = $categories[$categoryUid]; if (!$category) { @@ -90,5 +85,3 @@ class LatestController extends AbstractController { $this->view->assign('newsMetaData', $newsMetaData); } } - -?> diff --git a/Classes/Domain/Repository/NewsRepository.php b/Classes/Domain/Repository/NewsRepository.php index 867e94c..0bd3578 100644 --- a/Classes/Domain/Repository/NewsRepository.php +++ b/Classes/Domain/Repository/NewsRepository.php @@ -99,7 +99,7 @@ class NewsRepository extends AbstractRepository { ) { $query = $this->createQuery(); $constraints = NULL; - if ($categoryIds !== NULL && is_array($categoryIds)) { + if ($categoryIds !== NULL && count($categoryIds)) { $constraints[] = $query->in('pid', $categoryIds); } diff --git a/README.md b/README.md index 46c32ff..01608ce 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ extension itself provides two new doktypes, we can simply add a switch case to o to provide different rendering paths. Please look at the example below: ``` +lib.pageTemplate.default > lib.pageTemplate.default = FLUIDTEMPLATE lib.pageTemplate.default { file = EXT:project_theme/Resources/Private/Templates/Default.html @@ -19,6 +20,12 @@ lib.pageTemplate.default { 116 = TEXT 116.value = + 117 = COA + 117 { + 10 < tt_content.list.20.sgnews_latest + 20 < styles.content.col0 + } + # just show the content default < styles.content.col0 } @@ -31,7 +38,11 @@ lib.pageTemplate.default { 116 < tt_content.list.20.sgnews_singleview # show the category view of the news if the page type matches - 117 < tt_content.list.20.sgnews_listbycategory + 117 = COA + 117 { + 10 < tt_content.list.20.sgnews_listbycategory + 20 < styles.content.col1 + } # just show the content default < styles.content.col1 diff --git a/Resources/Private/Templates/ListByCategory/Index.html b/Resources/Private/Templates/ListByCategory/Index.html index 172ef2a..35795fd 100644 --- a/Resources/Private/Templates/ListByCategory/Index.html +++ b/Resources/Private/Templates/ListByCategory/Index.html @@ -3,7 +3,15 @@ {namespace sg=SGalinski\SgNews\ViewHelpers} <f:section name="main"> - <section class="content light-bg "> + <section class="content light-bg"> + <div class="container"> + <f:for each="{categories}" as="category"> + <h2 class="tx-sgnews-category-title">{category.subtitleWithFallbackToTitle}</h2> + </f:for> + </div> + </section> + + <section class="content light-bg"> <div class="container tx-sgnews-categories"> <ul class="tx-sgnews-list row"> <f:for each="{newsMetaData}" as="newsMetaDataEntry"> -- GitLab