-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TASK: Add a category filter #2
base: master
Are you sure you want to change the base?
Changes from 3 commits
b543678
c051630
91a9e61
5f1f19f
f871e0e
6fbb9a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
namespace JohannesSteu\Neos\News\Eel\FlowQueryOperations; | ||
|
||
/* * | ||
* This script belongs to the Flow package "JohannesSteu.Neos.News". * | ||
* */ | ||
|
||
use TYPO3\Eel\FlowQuery\Operations\AbstractOperation; | ||
use TYPO3\Eel\FlowQuery\FlowQuery; | ||
use TYPO3\Flow\Annotations as Flow; | ||
use TYPO3\TYPO3CR\Domain\Model\NodeInterface; | ||
|
||
/** | ||
* EEL operation to filter nodes by a given category. | ||
*/ | ||
class FilterByCategoryOperation extends AbstractOperation | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @var string | ||
*/ | ||
protected static $shortName = 'filterByCategory'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @var integer | ||
*/ | ||
protected static $priority = 100; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* We can only handle TYPO3CR Nodes. | ||
* | ||
* @param mixed $context | ||
* @return boolean | ||
*/ | ||
public function canEvaluate($context) | ||
{ | ||
return (isset($context[0]) && ($context[0] instanceof NodeInterface)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param FlowQuery $flowQuery the FlowQuery object | ||
* @param array $arguments First argument is the property to filter for, second is the category to filter for | ||
* @return mixed | ||
*/ | ||
public function evaluate(FlowQuery $flowQuery, array $arguments) | ||
{ | ||
if (!isset($arguments[0]) || empty($arguments[0])) { | ||
throw new \TYPO3\Eel\FlowQuery\FlowQueryException('needs a category to filter for', 1332492263); | ||
} else { | ||
$nodesWithCategorySet = []; | ||
|
||
$categoryNode = $arguments[0]; | ||
$nodes = $flowQuery->getContext(); | ||
|
||
foreach($nodes as $node) { | ||
/** @var $node NodeInterface */ | ||
$nodeCategories = $node->getProperty("categories"); | ||
foreach ($nodeCategories as $nodeCategory) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be renamed to $categoryNode There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $categoryNode already exists |
||
/** @var $nodeCategory Node */ | ||
if ($nodeCategory->getNodeData()->getProperty("uriPathSegment") == $categoryNode) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The check for a categoryNode shouldn't be done with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how can I pass to $arguments the complete object of the node? I tried, but it will only send the node path as string. So I have to get the node again and compare the node itself again. Isn't this way slower because I have to get the node from the repo first? And by the way the get parameter looks kind of ugly with the node path, looks more clear with just the uriPathSegement |
||
$nodesWithCategorySet[] = $node; | ||
} | ||
} | ||
|
||
} | ||
|
||
$flowQuery->setContext($nodesWithCategorySet); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
{namespace ts=TYPO3\TypoScript\ViewHelpers} | ||
|
||
<f:section name="newsFilter"> | ||
<f:if condition="{categoryFilter}"> | ||
<ts:render path="categoryFilterTemplate" context="{categoryFilter:categoryFilter}" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. context variables should als be named categories |
||
</f:if> | ||
<f:if condition="{dateFilter}"> | ||
<ts:render path="dateFilterTemplate" context="{dateFilter:dateFilter}" /> | ||
</f:if> | ||
|
@@ -22,4 +25,17 @@ | |
</li> | ||
</f:for> | ||
</ul> | ||
</f:section> | ||
</f:section> | ||
|
||
|
||
<f:section name="categoryFilter"> | ||
<ul class="news-categoryfilter"> | ||
<li class="headline">Themen / Kategorien</li> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the translate vh here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed it |
||
<li><neos:link.node node="{node}"><span class="news-categoryfilter__category">Alle</span></neos:link.node></li> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also Translate VH for this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed it |
||
<f:for each="{categoryFilter}" as="filter"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for each {categories} as category |
||
<li> | ||
<neos:link.node node="{node}" arguments="{category: '{filter.properties.uriPathSegment}'}"><span class="news-categoryfilter__category">{filter.properties.title}</span></neos:link.node> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't access .properties on a a node within fluid as it slows down rendering a lot |
||
</li> | ||
</f:for> | ||
</ul> | ||
</f:section> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,4 +38,13 @@ prototype(JohannesSteu.Neos.News:NewsFilter) < prototype(TYPO3.Neos:Content) { | |
|
||
dateFilter = ${dateFilter} | ||
} | ||
|
||
categoryFilter = ${q(site).find('[instanceof JohannesSteu.Neos.News:Category]').get()} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be named |
||
|
||
categoryFilterTemplate = TYPO3.TypoScript:Template { | ||
templatePath = 'resource://JohannesSteu.Neos.News/Private/Templates/NodeTypes/NewsFilter.html' | ||
sectionName = 'categoryFilter' | ||
|
||
categoryFilter = ${categoryFilter} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be renamed to categories |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,9 @@ prototype(JohannesSteu.Neos.News:NewsList) < prototype(Flowpack.Listable:ListNod | |
[email protected] = ${q(value).count() > 0 && q(value).removeImportantNews(respectImportant).get()} | ||
|
||
# apply newsfilter if set | ||
[email protected] = ${request.arguments.category != NULL ? q(value).filterByCategory(request.arguments.category).get() : value} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please prefix the argument with |
||
[email protected] = ${request.arguments.newsfilter-date != NULL ? q(value).filterByDateintervall('publishDate',request.arguments.newsfilter-date, '>').get() : value} | ||
|
||
} | ||
} | ||
|
||
|
@@ -54,8 +56,12 @@ prototype(TYPO3.Neos:ContentCollection)[email protected] = ${re | |
prototype(Flowpack.Listable:ListNode)[email protected] = ${request.pluginArguments.listable-paginate.currentPage} | ||
|
||
|
||
# Adjust cachces for newsfilter | ||
# Adjust caches for newsfilter | ||
[email protected] = ${request.arguments.newsfilter-date} | ||
prototype(TYPO3.Neos:Page)[email protected] = ${request.arguments.newsfilter-date} | ||
prototype(TYPO3.Neos:ContentCollection)[email protected] = ${request.arguments.newsfilter-date} | ||
prototype(Flowpack.Listable:ListNode)[email protected] = ${request.arguments.newsfilter-date} | ||
prototype(Flowpack.Listable:ListNode)[email protected] = ${request.arguments.newsfilter-date} | ||
[email protected] = ${request.arguments.category} | ||
prototype(TYPO3.Neos:Page)[email protected] = ${request.arguments.category} | ||
prototype(TYPO3.Neos:ContentCollection)[email protected] = ${request.arguments.category} | ||
prototype(Flowpack.Listable:ListNode)[email protected] = ${request.arguments.category} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$categoryNode
should be checked if it is an instance of Category