public function getRootPageId($pageId = 0, $forceFallback = false, $mountPointIdentifier = '')
    {
        /** @var Rootline $rootLine */
        $rootLine = GeneralUtility::makeInstance(Rootline::class);
        $rootPageId = intval($pageId) ?: intval($GLOBALS['TSFE']->id);

        // frontend
        if (!empty($GLOBALS['TSFE']->rootLine)) {
            $rootLine->setRootLineArray($GLOBALS['TSFE']->rootLine);
        }

        // fallback, backend
        if ($pageId != 0 && ($forceFallback || !$rootLine->getHasRootPage())) {
            /* @var $pageSelect PageRepository */
            $pageSelect = GeneralUtility::makeInstance(PageRepository::class);

            try {
                $rootLineArray = $pageSelect->getRootLine($pageId, $mountPointIdentifier);
            } catch (\RuntimeException $e) {
                $rootLineArray = [];
            }
            $rootLine->setRootLineArray($rootLineArray);
        }

        $rootPageFromRootLine = $rootLine->getRootPageId();

        return $rootPageFromRootLine === 0 ? $rootPageId : $rootPageFromRootLine;
    }
public function getRootPageId($pageId = 0, $forceFallback = false, $mountPointIdentifier = '')
    {
        /** @var Rootline $rootLine */
        $rootLine = GeneralUtility::makeInstance(Rootline::class);
        $rootPageId = intval($pageId) ?: intval($GLOBALS['TSFE']->id);

        // frontend
        if (!empty($GLOBALS['TSFE']->rootLine)) {
            $rootLine->setRootLineArray($GLOBALS['TSFE']->rootLine);
        }

        // fallback, backend
        if ($pageId != 0 && ($forceFallback || !$rootLine->getHasRootPage())) {
            /* @var $pageSelect PageRepository */
            $pageSelect = GeneralUtility::makeInstance(PageRepository::class);

            try {
                $rootLineArray = $pageSelect->getRootLine($pageId, $mountPointIdentifier);
            } catch (\RuntimeException $e) {
                $rootLineArray = [];
            }
            $rootLine->setRootLineArray($rootLineArray);
        }

        $rootPageFromRootLine = $rootLine->getRootPageId();

        return $rootPageFromRootLine === 0 ? $rootPageId : $rootPageFromRootLine;
    }
public function getRootPageId ( $ pageId = 0 , $ forceFallback = false , $ mountPointIdentifier = '' ) { /** @var Rootline $rootLine */ $ rootLine = GeneralUtility :: makeInstance ( Rootline :: class ) ; $ rootPageId = intval ( $ pageId ) ? : intval ( $ GLOBALS [ 'TSFE' ] -> id ) ; // frontend if ( ! empty ( $ GLOBALS [ 'TSFE' ] -> rootLine ) ) { $ rootLine -> setRootLineArray ( $ GLOBALS [ 'TSFE' ] -> rootLine ) ; } // fallback, backend if ( $ pageId != 0 && ( $ forceFallback || ! $ rootLine -> getHasRootPage ( ) ) ) { /* @var $pageSelect PageRepository */ $ pageSelect = GeneralUtility :: makeInstance ( PageRepository :: class ) ; try { $ rootLineArray = $ pageSelect -> getRootLine ( $ pageId , $ mountPointIdentifier ) ; } catch ( \ RuntimeException $ e ) { $ rootLineArray = [ ] ; } $ rootLine -> setRootLineArray ( $ rootLineArray ) ; } $ rootPageFromRootLine = $ rootLine -> getRootPageId ( ) ; return $ rootPageFromRootLine === 0 ? $ rootPageId : $ rootPageFromRootLine ; }
Determines the rootpage ID for a given page.

@param int $pageId A page ID somewhere in a tree.
@param bool $forceFallback Force the explicit detection and do not use the current frontend root line
@param string $mountPointIdentifier
@return int The page's tree branch's root page ID
Determines the rootpage ID for a given page .