@param PageInterface $page

@return mixed|void
185180
public function fixUrl(PageInterface $page)
    {
        if ($page->isInternal()) {
            $page->setUrl(null); // internal routes do not have any url ...

            return;
        }

        // hybrid page cannot be altered
        if (!$page->isHybrid()) {
            // make sure Page has a valid url
            if ($page->getParent()) {
                if (!$page->getSlug()) {
                    $page->setSlug(Page::slugify($page->getName()));
                }

                if ('/' === $page->getParent()->getUrl()) {
                    $base = '/';
                } elseif ('/' !== mb_substr($page->getParent()->getUrl(), -1)) {
                    $base = $page->getParent()->getUrl() . '/';
                } else {
                    $base = $page->getParent()->getUrl();
                }

                if ('page_slug' === $page->getRouteName()) {
                    $page->setUrl($base . $page->getSlug() . '/');
                }
            } else {
                // a parent page does not have any slug - can have a custom url ...
                $page->setSlug(null);
                $page->setUrl('/' . $page->getSlug());
            }
        }

        foreach ($page->getChildren() as $child) {
            $this->fixUrl($child);
        }
    }
9288
public function addPage($page)
    {
        if (is_array($page)) {
            $page = static::makePage($page);
        } elseif (is_string($page) or is_null($page)) {
            $title = $page;

            $page = app(PageInterface::class);
            $page->setTitle($title);
        }

        if (! ($page instanceof PageInterface)) {
            return;
        }

        $this->getPages()->push($page);

        return $page;
    }
1299456
public function initPage(Page $page)
	{
		/* @var $annotations PageUrlAnnotation[] */
		$annotations = $this->annotationManager->getClassAnnotations($page, '@page-url');

		if ( !$annotations || !($annotations[0] instanceof PageUrlAnnotation) ) {
			return $this;
		}

		$page->setUrlBuilder(
			$this->urlFactory->getBuilder(
				$this->urlNormalizer->normalize($annotations[0])
			)
		);

		return $this;
	}
507058
public static function description(PageInterface $page = null)
    {
        $page = $page ?: Router::getActivePage();
        $description = $page->getDescription() ?:
            ChunkFacade::get('text', 'standfirst', $page)->text();

        return strip_tags($description);
    }
1068988
public function preUpdate(PageInterface $page, PreUpdateEventArgs $event)
    {
        $em = $event->getEntityManager();
        $uow = $em->getUnitOfWork();

        if ($this->handlePage($page)) {
            $metadata = $em->getClassMetadata(get_class($page));
            $uow->recomputeSingleEntityChangeSet($metadata, $page);
        }

        /*$changeSet = $event->getEntityChangeSet();
        if (array_key_exists('enabled', $changeSet)) {
            if ($page->isEnabled()) {
                $this->discardPageRedirections($page);
            } else {
                $this->buildPageRedirections($page);
            }
        }*/
    }
782468
public function setActivePage(PageInterface $page)
    {
        $this->page = $page;
        $this->app->instance(PageModel::class, $page);

        return $this;
    }
820281
protected function updateSeoPage(PageInterface $pageInterface)
    {
        /** @var SeoPage $seoPage */
        $seoPage = $this->seoPage;

        if ($pageInterface instanceof SnapshotPageProxy) {
            $page = $pageInterface->getPage();
        } else {
            $page = $pageInterface;
        }

        $seoPage->addVar('page_internal', $page);

        $route = $page->getRouteName();

        if ('page_slug' === $route) {
            $seoPage->setLinkCanonical($this->getContainer()->get('router')->generate(
                $route,
                [
                    'path' => $page->getUrl(),
                ],
                0
            ));
        }

        if ('page_slug' === $route
            ||
            '_page_internal_error_not_found' === $route
        ) {
            $seoPage->build();
        }
    }
799020
public function setApplicationPage($page)
    {
        if (null !== $page) {
            Assert::string($page, 'The application page must be a string or null. Got: %s');
            Assert::notEmpty($page, 'The application page must not be empty.');
        }

        $this->applicationPage = $page;
    }
909229
public function page($page = null) {
        if ($page === null) {
            return $this->page;
        }

        $this->page = (int) $page;

        return $this;
    }
1331898
public function addPageFilter(Page $page)
    {
        if ($page && !$page->isRoot()) {
            $this->leftJoin('cc._mainnode', 'p')
                    ->leftJoin('p._section', 'sp')
                    ->andWhere('sp._root = :selectedPageRoot')
                    ->andWhere('sp._leftnode >= :selectedPageLeftnode')
                    ->andWhere('sp._rightnode <= :selectedPageRightnode')
                    ->setParameters([
                        'selectedPageRoot' => $page->getSection()->getRoot(),
                        'selectedPageLeftnode' => $page->getLeftnode(),
                        'selectedPageRightnode' => $page->getRightnode(),
                    ]);
        }
    }
733328
private function deletePageCache(PageInterface $page)
    {
        if (null !== $this->cache) {
            $this->cache->delete('ekyna_cms.page[route:' . $page->getRoute() . ']');
        }
    }
1058517
protected function initializeView(ViewInterface $view): void
    {
        $view->assignMultiple([
            'view' => $this->browserState->get('view'),
            'sortBy' => $this->browserState->get('sortBy'),
            'sortDirection' => $this->browserState->get('sortDirection'),
            'filter' => $this->browserState->get('filter'),
            'activeTag' => $this->browserState->get('activeTag'),
            'activeAssetCollection' => $this->browserState->get('activeAssetCollection'),
            'assetSources' => $this->assetSources,
            'variantsTabFeatureEnabled' => $this->settings['features']['variantsTab']['enable']
        ]);
    }
806515
public function getPageTemplates(HasPageTemplateInterface $page)
    {
        $pageTemplates = [];
        foreach ($page->getPageTemplates() as $pageTemplate) {
            if (is_string($pageTemplate)) {
                $pt = $this->parser->parse($pageTemplate);
            } elseif ($pageTemplate instanceof PageTemplateInterface) {
                $pt = $pageTemplate;
            } else {
                throw new \Exception("don't know how to handle the pageTemplate " . get_class($pageTemplate));
            }

            $pageTemplates[$pt->getName()] = $pt;
        }

        return $pageTemplates;
    }
684599
public function makePageSnapshot(PageInterface $page)
    {
        foreach ($page->getLayoutBlock() as $layoutBlock) {
            $layoutBlockContent = $this->registry->getManagerForClass($layoutBlock->getClassType())->getRepository($layoutBlock->getClassType())->find(
                $layoutBlock->getObjectId()
            );
            $layoutBlock->takeSnapshot($this->serializer->serialize($layoutBlockContent, 'json'));
        }

        $pageSnapshotClass = $this->pageSnapshotManager->getClassName();

        /** @var \Networking\InitCmsBundle\Model\PageSnapshotInterface $pageSnapshot */
        $pageSnapshot = new $pageSnapshotClass($page);
        $pageSnapshot->setVersionedData($this->serializer->serialize($page, 'json'))
            ->setPage($page);

        if ($oldPageSnapshot = $page->getSnapshot()) {
            $snapshotContentRoute = $oldPageSnapshot->getContentRoute();
        } else {
            $contentRouteClass = $this->contentRouteManager->getClassName();
            /** @var \Networking\InitCmsBundle\Model\ContentRouteInterface $snapshotContentRoute */
            $snapshotContentRoute = new $contentRouteClass();
        }

        $pageSnapshot->setContentRoute($snapshotContentRoute);
        $pageSnapshot->setPath(self::getPageRoutePath($page->getPath()));

        $om = $this->registry->getManagerForClass($pageSnapshotClass);
        $om->persist($pageSnapshot);
        $om->flush();

        $snapshotContentRoute->setPath(self::getPageRoutePath($page->getPath()));
        $snapshotContentRoute->setObjectId($pageSnapshot->getId());

        if ($oldPageSnapshot && ($oldPageSnapshot->getPath() != self::getPageRoutePath($page->getPath()))) {
            $this->phpCache->clean();
        }

        $om = $this->registry->getManagerForClass(get_class($snapshotContentRoute));
        $om->persist($snapshotContentRoute);
        $om->flush();
    }
213393
public function findByRequest(Request $request): ?PageInterface
    {
        if (null !== $route = $request->attributes->get('_route', null)) {
            return $this->findByRoute($route);
        }

        return null;
    }
634050
private function discardPageRedirections(PageInterface $page)
    {
        if ($page->isEnabled()) {
            /** @var \Ekyna\Bundle\CmsBundle\Model\PageTranslationInterface $translation */
            foreach ($page->getTranslations() as $locale => $translation) {
                // TODO use url generator or i18n routing prefix strategy
                $localePrefix = $locale != 'fr' ? '/' . $locale : '';
                $event = new DiscardRedirectionEvent($localePrefix . $translation->getPath());
                $this->dispatcher->dispatch(RedirectionEvents::DISCARD, $event);
            }
        }
    }
1038789
public function sort(PageInterface $page, $order_by = null, $order_dir = null, $sort_flags = null)
    {
        if ($order_by === null) {
            $order_by = $page->orderBy();
        }
        if ($order_dir === null) {
            $order_dir = $page->orderDir();
        }

        $path = $page->path();
        $children = $this->children[$path] ?? [];

        if (!$children) {
            return $children;
        }

        if (!isset($this->sort[$path][$order_by])) {
            $this->buildSort($path, $children, $order_by, $page->orderManual(), $sort_flags);
        }

        $sort = $this->sort[$path][$order_by];

        if ($order_dir !== 'asc') {
            $sort = array_reverse($sort);
        }

        return $sort;
    }