diff --git a/Classes/JohannesSteu/Neos/News/Eel/FlowQueryOperations/FilterByCategoryOperation.php b/Classes/JohannesSteu/Neos/News/Eel/FlowQueryOperations/FilterByCategoryOperation.php new file mode 100644 index 0000000..5aef919 --- /dev/null +++ b/Classes/JohannesSteu/Neos/News/Eel/FlowQueryOperations/FilterByCategoryOperation.php @@ -0,0 +1,83 @@ +getContext(); + + foreach($nodes as $node) { + /** @var $node NodeInterface */ + $nodeCategories = $node->getProperty("categories"); + foreach ($nodeCategories as $nodeCategory) { + + if ($nodeCategory->getNodeType()->getName() !== 'JohannesSteu.Neos.News:Category') { + throw new \TYPO3\Eel\FlowQuery\FlowQueryException('findByCategory() only accepts as parameter Nodes of type JohannesSteu.Neos.News:Category but '.$nodeCategory->getNodeType().' given', 1460741067); + } + + /** @var $nodeCategory Node */ + if ($nodeCategory->getNodeData()->getProperty("uriPathSegment") == $categoryNode) { + $nodesWithCategorySet[] = $node; + } + } + + } + + $flowQuery->setContext($nodesWithCategorySet); + } + } + +} diff --git a/Resources/Private/Templates/NodeTypes/NewsFilter.html b/Resources/Private/Templates/NodeTypes/NewsFilter.html index b4796d8..9688316 100644 --- a/Resources/Private/Templates/NodeTypes/NewsFilter.html +++ b/Resources/Private/Templates/NodeTypes/NewsFilter.html @@ -2,6 +2,9 @@ {namespace ts=TYPO3\TypoScript\ViewHelpers} + + + @@ -22,4 +25,15 @@ - \ No newline at end of file + + + + + + diff --git a/Resources/Private/TypoScript/NodeTypes/NewsFilter.ts2 b/Resources/Private/TypoScript/NodeTypes/NewsFilter.ts2 index 7af2550..9d65de7 100644 --- a/Resources/Private/TypoScript/NodeTypes/NewsFilter.ts2 +++ b/Resources/Private/TypoScript/NodeTypes/NewsFilter.ts2 @@ -38,4 +38,13 @@ prototype(JohannesSteu.Neos.News:NewsFilter) < prototype(TYPO3.Neos:Content) { dateFilter = ${dateFilter} } + + categories = ${q(site).find('[instanceof JohannesSteu.Neos.News:Category]').get()} + + categoryFilterTemplate = TYPO3.TypoScript:Template { + templatePath = 'resource://JohannesSteu.Neos.News/Private/Templates/NodeTypes/NewsFilter.html' + sectionName = 'categoryFilter' + + categories = ${categories} + } } \ No newline at end of file diff --git a/Resources/Private/TypoScript/NodeTypes/NewsList.ts2 b/Resources/Private/TypoScript/NodeTypes/NewsList.ts2 index 0e9e807..4c10242 100644 --- a/Resources/Private/TypoScript/NodeTypes/NewsList.ts2 +++ b/Resources/Private/TypoScript/NodeTypes/NewsList.ts2 @@ -35,7 +35,9 @@ prototype(JohannesSteu.Neos.News:NewsList) < prototype(Flowpack.Listable:ListNod collection.@process.respectImportantNews = ${q(value).count() > 0 && q(value).removeImportantNews(respectImportant).get()} # apply newsfilter if set + collection.@process.applyCategoryFilter = ${request.arguments.newsfilter-category != NULL ? q(value).filterByCategory(request.arguments.newsfilter-category).get() : value} collection.@process.applyDateFilter = ${request.arguments.newsfilter-date != NULL ? q(value).filterByDateintervall('publishDate',request.arguments.newsfilter-date, '>').get() : value} + } } @@ -54,8 +56,12 @@ prototype(TYPO3.Neos:ContentCollection).@cache.entryIdentifier.pagination = ${re prototype(Flowpack.Listable:ListNode).@cache.entryIdentifier.pagination = ${request.pluginArguments.listable-paginate.currentPage} -# Adjust cachces for newsfilter +# Adjust caches for newsfilter root.@cache.entryIdentifier.datefilter = ${request.arguments.newsfilter-date} prototype(TYPO3.Neos:Page).@cache.entryIdentifier.datefilter = ${request.arguments.newsfilter-date} prototype(TYPO3.Neos:ContentCollection).@cache.entryIdentifier.datefilter = ${request.arguments.newsfilter-date} -prototype(Flowpack.Listable:ListNode).@cache.entryIdentifier.datefilter = ${request.arguments.newsfilter-date} \ No newline at end of file +prototype(Flowpack.Listable:ListNode).@cache.entryIdentifier.datefilter = ${request.arguments.newsfilter-date} +root.@cache.entryIdentifier.categoryfilter = ${request.arguments.newsfilter-category} +prototype(TYPO3.Neos:Page).@cache.entryIdentifier.categoryfilter = ${request.arguments.newsfilter-category} +prototype(TYPO3.Neos:ContentCollection).@cache.entryIdentifier.categoryfilter = ${request.arguments.newsfilter-category} +prototype(Flowpack.Listable:ListNode).@cache.entryIdentifier.categoryfilter = ${request.arguments.newsfilter-category}