Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not fetch ContentViewhelper nodes recursively #157

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Classes/Fluid/ViewHelper/ComponentRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ protected function initializeComponentParams()
protected function extractContentViewHelpers(NodeInterface $node, RenderingContext $renderingContext): array
{
return array_reduce(
$this->extractViewHelpers($node, ContentViewHelper::class),
$this->extractViewHelpers($node, ContentViewHelper::class, false),
function (array $nodes, ViewHelperNode $node) use ($renderingContext) {
$slotArgument = $node->getArguments()['slot'] ?? null;
$slotName = ($slotArgument) ? $slotArgument->evaluate($renderingContext) : self::DEFAULT_SLOT;
Expand All @@ -569,7 +569,7 @@ function (array $nodes, ViewHelperNode $node) use ($renderingContext) {
* @param string $viewHelperClassName
* @return array
*/
protected function extractViewHelpers(NodeInterface $node, string $viewHelperClassName): array
protected function extractViewHelpers(NodeInterface $node, string $viewHelperClassName, bool $recursive = true): array
{
$viewHelperNodes = [];

Expand All @@ -581,9 +581,12 @@ protected function extractViewHelpers(NodeInterface $node, string $viewHelperCla
$viewHelperNodes[] = $node;
} else {
foreach ($node->getChildNodes() as $childNode) {
if ($recursive === false && $childNode instanceof ViewHelperNode && ($childNode->getViewHelperClassName() === ComponentViewHelper::class || $childNode->getUninitializedViewHelper() instanceof ComponentRenderer)) {
continue;
}
$viewHelperNodes = array_merge(
$viewHelperNodes,
$this->extractViewHelpers($childNode, $viewHelperClassName)
$this->extractViewHelpers($childNode, $viewHelperClassName, $recursive)
);
}
}
Expand Down
8 changes: 8 additions & 0 deletions Tests/Functional/SlotParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ public function renderDataProvider(): \Generator
'<test:contentSlot><fc:content><b>some html</b></fc:content></test:contentSlot><test:contentSlot><b>other html</b></test:contentSlot>',
"<b>some html</b>\n<b>other html</b>\n"
];
yield 'two nested component calls with named slots' => [
'<test:contentSlot><b>some html</b><test:contentSlot><fc:content><b>other html</b></fc:content></test:contentSlot></test:contentSlot>',
"<b>some html</b><b>other html</b>\n"
];
yield 'two different nested component calls with named slots' => [
'<test:contentSlot><fc:content><b>some html</b><test:twoSlotsAndContent><fc:content slot="slot1"><b>slot 1 html</b></fc:content><fc:content slot="slot2"><b>slot 2 html</b></fc:content>slot content</test:twoSlotsAndContent></fc:content></test:contentSlot>',
"<b>some html</b><b>slot 1 html</b>|<b>slot 2 html</b>|slot content\n"
];

// Check if slot object behaves correct for if statements
yield 'unspecified slot parameter' => [
Expand Down
Loading