Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
[BUGFIX] Handle nested fields views behaviour with Fluid standalone
Browse files Browse the repository at this point in the history
Couple of fixes that will fix certain issues when working with nested
fields in TYPO3 v8.
  • Loading branch information
romm committed Oct 25, 2017
1 parent a0a4d2c commit 3b5ac06
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions Classes/ViewHelpers/FieldViewHelper.php
Expand Up @@ -151,6 +151,9 @@ protected function renderLayoutView(array $templateArguments)
$templateArguments['fieldName'] = $fieldName;
$templateArguments['fieldId'] = ($templateArguments['fieldId']) ?: StringService::get()->sanitizeString('formz-' . $formObject->getName() . '-' . $fieldName);

$currentView = $this->viewHelperVariableContainer->getView();
$currentVariables = [];

$view = $this->fieldService->getView($layout);

/*
Expand All @@ -163,24 +166,55 @@ protected function renderLayoutView(array $templateArguments)
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '8.0.0', '<')) {
$view->setRenderingContext($this->renderingContext);
} else {
$renderingContext = $view->getRenderingContext();
$currentVariables = $this->renderingContext->getVariableProvider()->getAll();

/*
* Updating the view dependencies: the variable container as well as
* the controller context must be injected in the view.
*/
$renderingContext->setViewHelperVariableContainer($this->viewHelperVariableContainer);
$this->viewHelperVariableContainer->setView($view);

$view->getRenderingContext()->setViewHelperVariableContainer($this->viewHelperVariableContainer);

$view->setControllerContext($this->controllerContext);

$this->viewHelperVariableContainer->setView($view);
/*
* Adding current variables to the field view variables.
*/
$tmpVariables = $currentVariables;
ArrayUtility::mergeRecursiveWithOverrule($tmpVariables, $templateArguments);
$templateArguments = $tmpVariables;
}

$view->setLayoutRootPaths($layoutPaths);
$view->setPartialRootPaths($partialPaths);
$view->assignMultiple($templateArguments);

return $view->render();
$result = $view->render();

if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '8.0.0', '>=')) {
/*
* Because the view can be used several times in nested fields, we
* need to restore the variables after the view was rendered.
*/
$viewVariableProvider = $view->getRenderingContext()->getVariableProvider();

foreach ($viewVariableProvider->getAllIdentifiers() as $identifier) {
$viewVariableProvider->remove($identifier);
}

foreach ($currentVariables as $key => $value) {
$viewVariableProvider->add($key, $value);
}

/*
* Resetting the view of the variable container with the original
* view.
*/
$this->viewHelperVariableContainer->setView($currentView);
}

return $result;
}

/**
Expand Down

0 comments on commit 3b5ac06

Please sign in to comment.