Last active
December 8, 2015 08:08
-
-
Save khuppenbauer/9476129 to your computer and use it in GitHub Desktop.
FlowQueryOperation "slide" for TYPO3 Neos to get the property of parent Nodes
This file contains hidden or 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
backgroundImage = ${q(node).slide('backgroundImage').property('backgroundImage')} |
This file contains hidden or 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 Your\Package\TypoScript\FlowQueryOperations; | |
/* * | |
* This script belongs to the TYPO3 Flow package "TYPO3.Neos". * | |
* * | |
* It is free software; you can redistribute it and/or modify it under * | |
* the terms of the GNU General Public License, either version 3 of the * | |
* License, or (at your option) any later version. * | |
* * | |
* The TYPO3 project - inspiring people to share! * | |
* */ | |
use TYPO3\Eel\FlowQuery\FlowQuery; | |
use TYPO3\Eel\FlowQuery\Operations\AbstractOperation; | |
use TYPO3\Flow\Annotations as Flow; | |
use TYPO3\TYPO3CR\Domain\Model\NodeInterface; | |
/** | |
* "slide" operation working on TYPO3CR nodes. It iterates over all | |
* context elements and returns the node which matches the property | |
* specified as optional argument. | |
*/ | |
class SlideOperation extends AbstractOperation { | |
/** | |
* {@inheritdoc} | |
* | |
* @var string | |
*/ | |
static protected $shortName = 'slide'; | |
/** | |
* {@inheritdoc} | |
* | |
* @var integer | |
*/ | |
static protected $priority = 100; | |
/** | |
* {@inheritdoc} | |
* | |
* @param array (or array-like object) $context onto which this operation should be applied | |
* @return boolean TRUE if the operation can be applied onto the $context, FALSE otherwise | |
*/ | |
public function canEvaluate($context) { | |
return count($context) === 0 || (isset($context[0]) && ($context[0] instanceof NodeInterface)); | |
} | |
/** | |
* {@inheritdoc} | |
* | |
* @param FlowQuery $flowQuery the FlowQuery object | |
* @param array $arguments the arguments for this operation | |
* @return void | |
*/ | |
public function evaluate(FlowQuery $flowQuery, array $arguments) { | |
$output = array(); | |
foreach ($flowQuery->getContext() as $contextNode) { | |
while ($contextNode->getParent() !== NULL) { | |
$res = $contextNode->getProperty($arguments[0]); | |
if (!empty($res)) { | |
$output[] = $contextNode; | |
break; | |
} | |
$contextNode = $contextNode->getParent(); | |
} | |
} | |
$flowQuery->setContext($output); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment