Skip to content

When layout is disabled root view model is set as layout #78

@Xerkus

Description

@Xerkus

Bug Report

Normally layout is always present either via a constructor argument or via view model parameter override.

However, layout can be disabled and then bug happens where current view model becomes the layout and can be messed up from the child view scripts via layout view helper.

You may also pass a boolean false value to either addDefaultParam() or via the template variables for the layout key; doing so will disable the layout.

Here root view model is always selected as root:

private function renderModel(
ModelInterface $model,
RendererInterface $renderer,
?ModelInterface $root = null
): string {
if (! $root) {
$root = $model;
}

And here layout is not injected as a new root view model when layout is disabled.

$useLayout = false !== $viewModel->getVariable('layout', null);
if ($useLayout) {
$viewModel = $this->prepareLayout($viewModel);
}
return $this->renderModel($viewModel, $this->renderer);
}

When template name or a single level view model is passed layout helper is too late to mess up since it is already getting rendered when $this->layout() can be invoked.
Bug will manifest only with nested view models and when layout altering happens from inside children view scripts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions