Skip to content
Snippets Groups Projects
Commit 741b565c authored by Christian Kuhn's avatar Christian Kuhn Committed by Helmut Hummel
Browse files

[TASK] Fluid RenderViewHelper compilable

Resolves: #65451
Releases: master
Change-Id: Ia08ec9b586a2b080763f07ee2fe6e257ca484397
Reviewed-on: http://review.typo3.org/37453


Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: default avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: default avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: default avatarHelmut Hummel <helmut.hummel@typo3.org>
Tested-by: default avatarHelmut Hummel <helmut.hummel@typo3.org>
parent 512228f2
Branches
Tags
No related merge requests found
......@@ -11,6 +11,10 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
* The TYPO3 project - inspiring people to share! *
* */
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
/**
* ViewHelper that renders a section or a specified partial
*
......@@ -69,7 +73,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
*
* @api
*/
class RenderViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
class RenderViewHelper extends AbstractViewHelper implements CompilableInterface {
/**
* Renders the content.
......@@ -82,13 +86,39 @@ class RenderViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelp
* @api
*/
public function render($section = NULL, $partial = NULL, $arguments = array(), $optional = FALSE) {
$arguments = $this->loadSettingsIntoArguments($arguments);
return self::renderStatic(
array(
'section' => $section,
'partial' => $partial,
'arguments' => $arguments,
'optional' => $optional,
),
$this->buildRenderChildrenClosure(),
$this->renderingContext
);
}
/**
* Renders the content.
*
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
$section = $arguments['section'];
$partial = $arguments['partial'];
$optional = $arguments['optional'];
$arguments = static::loadSettingsIntoArguments($arguments['arguments'], $renderingContext);
$viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
if ($partial !== NULL) {
return $this->viewHelperVariableContainer->getView()->renderPartial($partial, $section, $arguments);
return $viewHelperVariableContainer->getView()->renderPartial($partial, $section, $arguments);
} elseif ($section !== NULL) {
return $this->viewHelperVariableContainer->getView()->renderSection($section, $arguments, $optional);
return $viewHelperVariableContainer->getView()->renderSection($section, $arguments, $optional);
}
return '';
}
......@@ -96,11 +126,13 @@ class RenderViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelp
* If $arguments['settings'] is not set, it is loaded from the TemplateVariableContainer (if it is available there).
*
* @param array $arguments
* @param RenderingContextInterface $renderingContext
* @return array
*/
protected function loadSettingsIntoArguments($arguments) {
if (!isset($arguments['settings']) && $this->templateVariableContainer->exists('settings')) {
$arguments['settings'] = $this->templateVariableContainer->get('settings');
static protected function loadSettingsIntoArguments($arguments, RenderingContextInterface $renderingContext) {
$templateVariableContainer = $renderingContext->getTemplateVariableContainer();
if (!isset($arguments['settings']) && $templateVariableContainer->exists('settings')) {
$arguments['settings'] = $templateVariableContainer->get('settings');
}
return $arguments;
}
......
......@@ -42,7 +42,7 @@ class RenderViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewH
);
$this->templateVariableContainer->add('settings', 'theSettings');
$actual = $this->viewHelper->_call('loadSettingsIntoArguments', $arguments);
$actual = $this->viewHelper->_call('loadSettingsIntoArguments', $arguments, $this->renderingContext);
$this->assertEquals($expected, $actual);
}
......@@ -60,7 +60,7 @@ class RenderViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewH
);
$this->templateVariableContainer->add('settings', 'theSettings');
$actual = $this->viewHelper->_call('loadSettingsIntoArguments', $arguments);
$actual = $this->viewHelper->_call('loadSettingsIntoArguments', $arguments, $this->renderingContext);
$this->assertEquals($expected, $actual);
}
......@@ -75,7 +75,7 @@ class RenderViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewH
'someArgument' => 'someValue'
);
$actual = $this->viewHelper->_call('loadSettingsIntoArguments', $arguments);
$actual = $this->viewHelper->_call('loadSettingsIntoArguments', $arguments, $this->renderingContext);
$this->assertEquals($expected, $actual);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment