Skip to content

Instantly share code, notes, and snippets.

@futjikato
Created January 23, 2016 17:54
Show Gist options
  • Save futjikato/02d3717e99d51e801995 to your computer and use it in GitHub Desktop.
Save futjikato/02d3717e99d51e801995 to your computer and use it in GitHub Desktop.
Neos FlowQuery Depth filter
<?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