Skip to content

Commit

Permalink
TASK: Runtime remove magic fusion jsonSerialize again
Browse files Browse the repository at this point in the history
The Neos `FusionView` is forward compatible for this change neos/flow-development-collection#3286
Assign should be used for setting the request:
```
$view->assign('request"', $this->request)
```
  • Loading branch information
mhsdesign committed Feb 25, 2024
1 parent bf8b9ef commit 198c755
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions Neos.Neos/Classes/View/FusionView.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\Controller\ControllerContext;
use Neos\Flow\Mvc\View\AbstractView;
use Neos\Flow\Security\Context;
use Neos\Fusion\Core\FusionGlobals;
Expand Down Expand Up @@ -52,6 +54,12 @@ class FusionView extends AbstractView
#[Flow\Inject]
protected RenderingModeService $renderingModeService;

/**
* Via {@see assign} request using the "request" key,
* will be available also as Fusion global in the runtime.
*/
protected ?ActionRequest $assignedActionRequest = null;

/**
* Renders the view
*
Expand Down Expand Up @@ -196,10 +204,10 @@ protected function getFusionRuntime(Node $currentSiteNode)

$renderingMode = $this->renderingModeService->findByName($this->getOption('renderingModeName'));

$fusionGlobals = FusionGlobals::fromArray([
'request' => $this->controllerContext->getRequest(),
$fusionGlobals = FusionGlobals::fromArray(array_filter([
'request' => $this->assignedActionRequest,
'renderingMode' => $renderingMode
]);
]));
$this->fusionRuntime = $this->runtimeFactory->createFromConfiguration(
$fusionConfiguration,
$fusionGlobals
Expand All @@ -220,7 +228,30 @@ protected function getFusionRuntime(Node $currentSiteNode)
*/
public function assign($key, $value): AbstractView
{
if ($key === 'request') {
// the request cannot be used as "normal" fusion variable and must be treated as FusionGlobal
// to for example not cache it accidentally
// additionally we need it for special request based handling in the view
$this->assignedActionRequest = $value;
return $this;
}
$this->fusionRuntime = null;
return parent::assign($key, $value);
}

/**
* Legacy layer to set the request for this view if not set already.
*
* Please use {@see assign} with "request" instead
*
* $view->assign('request"', $this->request)
*
* @deprecated with Neos 9
*/
public function setControllerContext(ControllerContext $controllerContext)
{
if (!$this->assignedActionRequest) {
$this->assignedActionRequest = $controllerContext->getRequest();
}
}
}

0 comments on commit 198c755

Please sign in to comment.