Skip to content

Commit

Permalink
[BUGFIX] Fix open pageTree status
Browse files Browse the repository at this point in the history
To determine the opened page branch, the uc path must be
BackendComponents.States.Pagetree.stateHash
instead of browseTrees.browsePages.

The configuration must also contain the following structure

[
  1_1234 => 1,
  1_3456 => 1
]

instead of

[
  1 => [
     1234,
     3456
  ]
]

Otherwise the page won't be expanded properly.

Resolves: #90985
Releases: master, 10.4
Change-Id: I63fb967c3d47286f24e4e469c4947a3c09047605
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64109
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
utrotzek authored and bmack committed Apr 27, 2021
1 parent 9cbec07 commit a3bfe28
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
9 changes: 5 additions & 4 deletions typo3/sysext/backend/Classes/Utility/BackendUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,14 @@ public static function openPageTree($pid, $clearExpansion)
if ($clearExpansion) {
$expandedPages = [];
} else {
$expandedPages = json_decode($beUser->uc['browseTrees']['browsePages'], true);
$expandedPages = $beUser->uc['BackendComponents']['States']['Pagetree']['stateHash'];
}
// Get rootline:
$rL = self::BEgetRootLine($pid);
// First, find out what mount index to use (if more than one DB mount exists):
$mountIndex = 0;
$mountKeys = array_flip($beUser->returnWebmounts());
$mountKeys = $beUser->returnWebmounts();

foreach ($rL as $rLDat) {
if (isset($mountKeys[$rLDat['uid']])) {
$mountIndex = $mountKeys[$rLDat['uid']];
Expand All @@ -516,10 +517,10 @@ public static function openPageTree($pid, $clearExpansion)
}
// Traverse rootline and open paths:
foreach ($rL as $rLDat) {
$expandedPages[$mountIndex][$rLDat['uid']] = 1;
$expandedPages[$mountIndex . '_' . $rLDat['uid']] = '1';
}
// Write back:
$beUser->uc['browseTrees']['browsePages'] = json_encode($expandedPages);
$beUser->uc['BackendComponents']['States']['Pagetree']['stateHash'] = $expandedPages;
$beUser->writeUC();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace TYPO3\CMS\Backend\Tests\Functional\Utility;

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class BackendUtilityTest extends FunctionalTestCase
{
public function setUp(): void
{
parent::setUp();
$this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
$this->setUpBackendUserFromFixture(1);
}

/**
* @test
*/
public function givenPageIdCanBeExpanded(): void
{
$backendUser = $this->getBackendUser();
$backendUser->groupData['webmounts'] = '1';

BackendUtility::openPageTree(5, false);

$expectedSiteHash = [
'1_5' => '1',
'1_1' => '1',
'1_0' => '1'
];
$actualSiteHash = $backendUser->uc['BackendComponents']['States']['Pagetree']['stateHash'];
self::assertSame($expectedSiteHash, $actualSiteHash);
}

/**
* @test
*/
public function otherBranchesCanBeClosedWhenOpeningPage(): void
{
$backendUser = $this->getBackendUser();
$backendUser->groupData['webmounts'] = '1';

BackendUtility::openPageTree(5, false);
BackendUtility::openPageTree(4, true);

//the complete branch of uid => 5 should be closed here
$expectedSiteHash = [
'1_4' => '1',
'1_3' => '1',
'1_2' => '1',
'1_1' => '1',
'1_0' => '1'
];
$actualSiteHash = $backendUser->uc['BackendComponents']['States']['Pagetree']['stateHash'];
self::assertSame($expectedSiteHash, $actualSiteHash);
}

private function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
}

0 comments on commit a3bfe28

Please sign in to comment.