/** * Adds the rootline of a given node to the tree expansion state and adds the node * itself as the current selected page. This leads to the expansion and selection of * the node in the tree after a refresh. * * @static * @param string $stateId * @param int $nodeId * @return array */ public static function addRootlineOfNodeToStateHash($stateId, $nodeId) { $mountPoints = array_map('intval', $GLOBALS['BE_USER']->returnWebmounts()); if (empty($mountPoints)) { $mountPoints = array(0); } $mountPoints[] = (int) $GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint']; $mountPoints = array_unique($mountPoints); /** @var $userSettingsController \TYPO3\CMS\Backend\Controller\UserSettingsController */ $userSettingsController = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Controller\UserSettingsController::class); $state = $userSettingsController->process('get', 'BackendComponents.States.' . $stateId); if (empty($state)) { $state = new \StdClass(); $state->stateHash = new \StdClass(); } $state->stateHash = (object) $state->stateHash; $rootline = BackendUtility::BEgetRootLine($nodeId, '', $GLOBALS['BE_USER']->workspace != 0); $rootlineIds = array(); foreach ($rootline as $pageData) { $rootlineIds[] = (int) $pageData['uid']; } foreach ($mountPoints as $mountPoint) { if (!in_array($mountPoint, $rootlineIds, true)) { continue; } $isFirstNode = true; foreach ($rootline as $pageData) { $node = Commands::getNewNode($pageData, $mountPoint); if ($isFirstNode) { $isFirstNode = false; $state->stateHash->lastSelectedNode = $node->calculateNodeId(); } else { $state->stateHash->{$node->calculateNodeId('')} = 1; } } } $userSettingsController->process('set', 'BackendComponents.States.' . $stateId, $state); return (array) $state->stateHash; }
/** * Adds the rootline of a given node to the tree expansion state and adds the node * itself as the current selected page. This leads to the expansion and selection of * the node in the tree after a refresh. * * @static * @param string $stateId * @param integer $nodeId * @return array */ public static function addRootlineOfNodeToStateHash($stateId, $nodeId) { $mountPoints = array_map('intval', $GLOBALS['BE_USER']->returnWebmounts()); if (count($mountPoints) == 0) { $mountPoints = array(0); } $mountPoints[] = (int) $GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint']; $mountPoints = array_unique($mountPoints); /** @var $userSettings \TYPO3\CMS\Backend\User\ExtDirect\BackendUserSettingsDataProvider */ $userSettings = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\User\\ExtDirect\\BackendUserSettingsDataProvider'); $state = $userSettings->get('BackendComponents.States.' . $stateId); $state->stateHash = (object) $state->stateHash; $rootline = BackendUtility::BEgetRootLine($nodeId, '', $GLOBALS['BE_USER']->workspace != 0); $rootlineIds = array(); foreach ($rootline as $pageData) { $rootlineIds[] = (int) $pageData['uid']; } foreach ($mountPoints as $mountPoint) { if (!in_array($mountPoint, $rootlineIds, TRUE)) { continue; } $isFirstNode = TRUE; foreach ($rootline as $pageData) { $node = Commands::getNewNode($pageData, $mountPoint); if ($isFirstNode) { $isFirstNode = FALSE; $state->stateHash->lastSelectedNode = $node->calculateNodeId(); } else { $state->stateHash->{$node->calculateNodeId('')} = 1; } } } $userSettings->set('BackendComponents.States.' . $stateId, $state); return (array) $state->stateHash; }
/** * Returns the page tree mounts for the current user * * Note: If you add the search filter parameter, the nodes will be filtered by this string. * * @param string $searchFilter * @return \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection */ public function getTreeMounts($searchFilter = '') { /** @var $nodeCollection \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection */ $nodeCollection = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection::class); $isTemporaryMountPoint = false; $rootNodeIsVirtual = false; $mountPoints = (int) $GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint']; if (!$mountPoints) { $mountPoints = array_map('intval', $GLOBALS['BE_USER']->returnWebmounts()); $mountPoints = array_unique($mountPoints); if (!in_array(0, $mountPoints)) { $rootNodeIsVirtual = true; // use a virtual root // the real mountpoints will be fetched in getNodes() then // since those will be the "subpages" of the virtual root $mountPoints = [0]; } } else { $isTemporaryMountPoint = true; $mountPoints = [$mountPoints]; } if (empty($mountPoints)) { return $nodeCollection; } foreach ($mountPoints as $mountPoint) { if ($mountPoint === 0) { $sitename = 'TYPO3'; if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] !== '') { $sitename = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']; } $record = ['uid' => 0, 'title' => $sitename]; $subNode = Commands::getNewNode($record); $subNode->setLabelIsEditable(false); if ($rootNodeIsVirtual) { $subNode->setType('virtual_root'); $subNode->setIsDropTarget(false); } else { $subNode->setType('pages_root'); $subNode->setIsDropTarget(true); } } else { if (in_array($mountPoint, $this->hiddenRecords)) { continue; } $record = $this->getRecordWithWorkspaceOverlay($mountPoint); if (!$record) { continue; } $subNode = Commands::getNewNode($record, $mountPoint); if ($this->showRootlineAboveMounts && !$isTemporaryMountPoint) { $rootline = Commands::getMountPointPath($record['uid']); $subNode->setReadableRootline($rootline); } } if (count($mountPoints) <= 1) { $subNode->setExpanded(true); $subNode->setCls('typo3-pagetree-node-notExpandable'); } $subNode->setIsMountPoint(true); $subNode->setDraggable(false); if ($searchFilter === '') { $childNodes = $this->getNodes($subNode, $mountPoint); } else { $childNodes = $this->getFilteredNodes($subNode, $searchFilter, $mountPoint); $subNode->setExpanded(true); } $subNode->setChildNodes($childNodes); $nodeCollection->append($subNode); } foreach ($this->processCollectionHookObjects as $hookObject) { /** @var $hookObject \TYPO3\CMS\Backend\Tree\Pagetree\CollectionProcessorInterface */ $hookObject->postProcessGetTreeMounts($searchFilter, $nodeCollection); } return $nodeCollection; }
/** * Gets the path steps for a given page. * This methods considers multiple mount points, * thus the returned array is multidimensional, e.g. * * array( * array('p0', 'p1', 'p13', 'p44'), * array('p0', 'p13-1', 'p44-1'), * ) * * @param int $pageId * @return array */ public static function getNodePaths($pageId) { $pagePaths = array(); $mountPoints = array_map('intval', static::getBackendUser()->returnWebmounts()); if (empty($mountPoints)) { $mountPoints = array(0); } $mountPoints[] = (int) static::getBackendUser()->uc['pageTree_temporaryMountPoint']; $mountPoints = array_unique($mountPoints); $rootLine = BackendUtility::BEgetRootLine($pageId, '', (int) static::getBackendUser()->workspace !== 0); $rootLineIds = array(); foreach ($rootLine as $rootLineLevel) { $rootLineIds[] = (int) $rootLineLevel['uid']; } foreach ($mountPoints as $mountPoint) { $pagePath = array(); if (!in_array($mountPoint, $rootLineIds, true)) { continue; } foreach ($rootLine as $rootLineLevel) { $node = Commands::getNewNode($rootLineLevel, $mountPoint); array_unshift($pagePath, $node->calculateNodeId()); // Break if mount-point has been reached if ($mountPoint === (int) $rootLineLevel['uid']) { break; } } // Attach valid partial root-lines if (!empty($pagePath)) { if ($mountPoint !== 0) { array_unshift($pagePath, Commands::getNewNode(array('uid' => 0))->calculateNodeId()); } $pagePaths[] = $pagePath; } } return $pagePaths; }