Created
January 23, 2016 17:54
-
-
Save futjikato/02d3717e99d51e801995 to your computer and use it in GitHub Desktop.
Neos FlowQuery Depth filter
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 TYPO3\NeosDemoTypo3Org\FlowQuery\Operation; | |
use TYPO3\Eel\FlowQuery\FlowQuery; | |
use TYPO3\Eel\FlowQuery\Operations\AbstractOperation; | |
class DepthOperation extends AbstractOperation | |
{ | |
/** | |
* {@inheritdoc} | |
* | |
* @var string | |
*/ | |
static protected $shortName = 'depth'; | |
/** | |
* {@inheritdoc} | |
* | |
* @param FlowQuery $flowQuery the FlowQuery object | |
* @param array $arguments the arguments for this operation | |
* @return void | |
*/ | |
public function evaluate(FlowQuery $flowQuery, array $arguments) | |
{ | |
if (!isset($arguments[0])) { | |
throw new \TYPO3\Eel\FlowQuery\FlowQueryException("Depth argument expects depth to select as first argument"); | |
} | |
$depth = $arguments[0]; | |
$filter = null; | |
if (isset($arguments[1])) { | |
$filter = $arguments[1]; | |
} | |
if (isset($filter)) { | |
$flowQuery->pushOperation('filter', array($filter)); | |
} | |
for ($i = 0; $i < $depth; $i++) { | |
$flowQuery->pushOperation('children', array()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment