Last active
September 18, 2017 09:13
-
-
Save hlubek/62725180de2af8246b0e340282a4d98a to your computer and use it in GitHub Desktop.
Extended FlowQuery FilterOperation with array support (reference and references)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyProject\Neos\Blog\Eel\FlowQueryOperations; | |
use TYPO3\TYPO3CR\Domain\Model\NodeInterface; | |
/** | |
* Override the default FilterOperation to support filtering of NodeInterface values | |
* (reference) by identifier (with "=") or references by containing a value ("*=") | |
*/ | |
class FilterOperation extends \TYPO3\TYPO3CR\Eel\FlowQueryOperations\FilterOperation | |
{ | |
/** | |
* {@inheritdoc} | |
* | |
* @var integer | |
*/ | |
protected static $priority = 200; | |
/** | |
* {@inheritdoc} | |
* | |
* @param mixed $value | |
* @param string $operator | |
* @param mixed $operand | |
* @return boolean | |
*/ | |
protected function evaluateOperator($value, $operator, $operand) | |
{ | |
if ($value instanceof NodeInterface && ($operator === '=' || $operator === '!=')) { | |
$value = $value->getIdentifier(); | |
} elseif (is_array($value) && $operator === '*=') { | |
foreach ($value as $item) { | |
if ($this->evaluateOperator($item, '=', $operand)) { | |
return true; | |
} | |
} | |
return false; | |
} | |
return parent::evaluateOperator($value, $operator, $operand); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment