Created
August 15, 2012 12:24
-
-
Save Allisone/3359695 to your computer and use it in GitHub Desktop.
A service class that enables you to render a ViewHelper from within a ViewHelper
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 Wojtowicz\Utilities\Service; | |
use TYPO3\FLOW3\Annotations as FLOW3; | |
/** | |
* Created by Sebastian Wojtowicz. | |
* Date: 15.08.12 - 13:57 | |
* | |
* @FLOW3\Scope("singleton") | |
*/ | |
class ViewHelperHelper { | |
/** | |
* @var \TYPO3\FLOW3\Object\ObjectManagerInterface | |
*/ | |
protected $objectManager; | |
/** | |
* @param \TYPO3\FLOW3\Object\ObjectManagerInterface $objectManager | |
* @return void | |
*/ | |
public function injectObjectManager(\TYPO3\FLOW3\Object\ObjectManagerInterface $objectManager) { | |
$this->objectManager = $objectManager; | |
} | |
/** | |
* @param string $viewHelperName | |
* @param array $arguments | |
* | |
* @return \TYPO3\Fluid\Core\Parser\SyntaxTree\ViewHelperNode | |
*/ | |
public function getViewHelperNodeWithTextArgumentsAdHoc($viewHelperName, $arguments){ | |
$viewHelperNodeArguments = array(); | |
foreach ($arguments as $argument_key => $argument_value){ | |
$node = new \TYPO3\Fluid\Core\Parser\SyntaxTree\RootNode(); | |
$node->addChildNode(new \TYPO3\Fluid\Core\Parser\SyntaxTree\TextNode((string)$argument_value)); | |
$viewHelperNodeArguments[$argument_key] = $node; | |
} | |
$viewHelper = $this->objectManager->get($viewHelperName); | |
$node = new \TYPO3\Fluid\Core\Parser\SyntaxTree\ViewHelperNode($viewHelper,$viewHelperNodeArguments); | |
return $node; //output via $node->evaluate($renderingContext); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment