protected function calculateClosestPageIdWithActiveTemplate($startPageId)
    {
        $rootLine = $this->pageRepository->getRootLine($startPageId);
        // when no rootline is present the startpage it's self is the closest page
        if (!is_array($rootLine)) {
            return $startPageId;
        }

        $closestPageIdWithTemplate = $this->systemTemplateRepository->findOneClosestPageIdWithActiveTemplateByRootLine($rootLine);
        if ($closestPageIdWithTemplate === 0) {
            return $startPageId;
        }

        return (int)$closestPageIdWithTemplate;
    }