Commit 1072b2a3 authored by Benni Mack's avatar Benni Mack Committed by Oliver Bartsch
Browse files

[TASK] Ensure that hidden pages are not rendered as subpages in HMENU

This change adds tests to a very old issue to ensure
that a page with only hidden subpages is not marked
as IFSUB etc.

MenuProcessor is extended to set a "hasSubpages" flag
when IFSUB, CURIFSUB or ACTIFSUB is set.

Resolves: #22190
Releases: main, 11.5
Change-Id: Ia9b73e8ae1028eafa94ba4fa5ca0dacf2562c074
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72888

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent 15c5d339
......@@ -199,6 +199,11 @@ class MenuProcessor implements DataProcessorInterface
'value' => '0',
'wrap' => ',"spacer":|',
],
'60' => 'TEXT',
'60.' => [
'value' => '0',
'wrap' => ',"hasSubpages":|',
],
],
],
];
......@@ -396,16 +401,19 @@ class MenuProcessor implements DataProcessorInterface
}
$this->menuConfig[$i . '.']['IFSUB'] = '1';
$this->menuConfig[$i . '.']['IFSUB.'] = $this->menuConfig[$i . '.']['NO.'];
$this->menuConfig[$i . '.']['IFSUB.']['stdWrap.']['cObject.']['60.']['value'] = '1';
$this->menuConfig[$i . '.']['ACT'] = '1';
$this->menuConfig[$i . '.']['ACT.'] = $this->menuConfig[$i . '.']['NO.'];
$this->menuConfig[$i . '.']['ACT.']['stdWrap.']['cObject.']['30.']['value'] = '1';
$this->menuConfig[$i . '.']['ACTIFSUB'] = '1';
$this->menuConfig[$i . '.']['ACTIFSUB.'] = $this->menuConfig[$i . '.']['ACT.'];
$this->menuConfig[$i . '.']['ACTIFSUB.']['stdWrap.']['cObject.']['60.']['value'] = '1';
$this->menuConfig[$i . '.']['CUR'] = '1';
$this->menuConfig[$i . '.']['CUR.'] = $this->menuConfig[$i . '.']['ACT.'];
$this->menuConfig[$i . '.']['CUR.']['stdWrap.']['cObject.']['40.']['value'] = '1';
$this->menuConfig[$i . '.']['CURIFSUB'] = '1';
$this->menuConfig[$i . '.']['CURIFSUB.'] = $this->menuConfig[$i . '.']['CUR.'];
$this->menuConfig[$i . '.']['CURIFSUB.']['stdWrap.']['cObject.']['60.']['value'] = '1';
if (($this->menuConfig['special'] ?? '') === 'language') {
$this->menuConfig[$i . '.']['USERDEF1'] = $this->menuConfig[$i . '.']['NO'];
$this->menuConfig[$i . '.']['USERDEF1.'] = $this->menuConfig[$i . '.']['NO.'];
......
......@@ -157,6 +157,10 @@ entities:
- self: {id: 2120, title: 'Jane Doe', slug: '/jane'}
children:
- self: {id: 2121, title: 'About', slug: '/about-jane'}
- self: {id: 2130, title: 'Malloy Doe', slug: '/malloy'}
children:
- self: {id: 2131, title: 'About Malloy - Hidden', hidden: 1, 'slug': '/malloy/about'}
- self: {id: 2132, title: 'Malloys History - Hidden', hidden: 1, 'slug': '/malloy/history'}
- self: {id: 2700, title: 'Announcements & News', type: *pageMount, mount: 7100, slug: '/news'}
- self: {id: 2800, title: 'What is a blog on Wikipedia ', type: *pageExternalUrl, url: 'https://en.wikipedia.org/wiki/Blog', slug: '/what-is-a-blog', target: 'a_new_tab' }
- self: {id: 2900, title: 'What is Wikipedia in a separate window ', type: *pageExternalUrl, url: 'https://en.wikipedia.org/', slug: '/wikipedia' }
......
......@@ -783,6 +783,10 @@ class SlugLinkGeneratorTest extends AbstractTestCase
'link' => 'https://blog.acme.com/jane/jane',
'target' => '',
],
[
'title' => 'Malloy Doe',
'link' => '/malloy',
],
],
],
1 =>
......@@ -847,6 +851,62 @@ class SlugLinkGeneratorTest extends AbstractTestCase
self::assertSame($expectation, $json);
}
/**
* @test
*/
public function hierarchicalMenuDoesNotShowHiddenPagesAsSubMenu(): void
{
$expectation = [
[
'title' => 'John Doe',
'link' => 'https://blog.acme.com/john/john',
'hasSubpages' => 1,
'children' => [
[
'title' => 'About',
'link' => 'https://blog.acme.com/john/about-john',
'hasSubpages' => 0,
],
],
],
[
'title' => 'Jane Doe',
'link' => 'https://blog.acme.com/jane/jane',
'hasSubpages' => 1,
'children' => [
[
'title' => 'About',
'link' => 'https://blog.acme.com/jane/about-jane',
'hasSubpages' => 0,
],
],
],
[
'title' => 'Malloy Doe',
'link' => '/malloy',
'hasSubpages' => 0,
],
];
$response = $this->executeFrontendSubRequest(
(new InternalRequest('https://blog.acme.com/'))
->withPageId(2130)
->withInstructions([
$this->createHierarchicalMenuProcessorInstruction([
'levels' => 2,
'entryLevel' => 1,
'expandAll' => 1,
'includeSpacer' => 1,
'titleField' => 'title',
]),
])
);
$json = json_decode((string)$response->getBody(), true);
$json = $this->filterMenu($json, ['title', 'link', 'hasSubpages']);
self::assertSame($expectation, $json);
}
public function hierarchicalMenuSetsActiveStateProperlyDataProvider(): array
{
return [
......
Markdown is supported
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