Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
Copy link
Owner

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

$nodes = $flowQuery->getContext();

foreach($nodes as $node) {
/** @var $node NodeInterface */
$nodeCategories = $node->getProperty("categories");
foreach ($nodeCategories as $nodeCategory) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be renamed to $categoryNode

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$categoryNode already exists

/** @var $nodeCategory Node */
if ($nodeCategory->getNodeData()->getProperty("uriPathSegment") == $categoryNode) {
Copy link
Owner

@johannessteu johannessteu Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for a categoryNode shouldn't be done with the uriPathSegement but with the nodetype and identifer or path. With this implementation you could call the categroyFilter with an non category node

Copy link
Author

Choose a reason for hiding this comment

The 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);
}
}

}
18 changes: 17 additions & 1 deletion Resources/Private/Templates/NodeTypes/NewsFilter.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
{namespace ts=TYPO3\TypoScript\ViewHelpers}

<f:section name="newsFilter">
<f:if condition="{categoryFilter}">
<ts:render path="categoryFilterTemplate" context="{categoryFilter:categoryFilter}" />
Copy link
Owner

Choose a reason for hiding this comment

The 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>
Expand All @@ -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>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the translate vh here

Copy link
Author

Choose a reason for hiding this comment

The 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>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also Translate VH for this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it

<f:for each="{categoryFilter}" as="filter">
Copy link
Owner

Choose a reason for hiding this comment

The 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>
Copy link
Owner

Choose a reason for hiding this comment

The 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>
9 changes: 9 additions & 0 deletions Resources/Private/TypoScript/NodeTypes/NewsFilter.ts2
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be named categories as it contains a set of catgeories, not a filter itself


categoryFilterTemplate = TYPO3.TypoScript:Template {
templatePath = 'resource://JohannesSteu.Neos.News/Private/Templates/NodeTypes/NewsFilter.html'
sectionName = 'categoryFilter'

categoryFilter = ${categoryFilter}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be renamed to categories

}
}
10 changes: 8 additions & 2 deletions Resources/Private/TypoScript/NodeTypes/NewsList.ts2
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please prefix the argument with newsfilter as category is pretty much global and could also be used for something different

[email protected] = ${request.arguments.newsfilter-date != NULL ? q(value).filterByDateintervall('publishDate',request.arguments.newsfilter-date, '>').get() : value}

}
}

Expand All @@ -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}