Builds redirections for the page.

@param PageInterface $page
173895
private function buildPageRedirections(PageInterface $page)
    {
        if (!$page->isEnabled()) {
            $redirections = [];

            // Store "from" paths for each locale
            $locales = [];
            /** @var \Ekyna\Bundle\CmsBundle\Model\PageTranslationInterface $translation */
            foreach ($page->getTranslations() as $locale => $translation) {
                $locales[$locale] = $locale;
                $redirections[$locale] = [
                    'from' => $translation->getPath(),
                ];
            }

            // Find the first enabled ancestor
            $parentPage = $page;
            while (null !== $parentPage = $parentPage->getParent()) {
                if ($parentPage->isEnabled()) {
                    // Store "to" paths for each locale
                    foreach ($parentPage->getTranslations() as $locale => $translation) {
                        if (array_key_exists($locale, $redirections)) {
                            $redirections[$locale]['to'] = $translation->getPath();
                            unset($locales[$locale]);
                        }
                        // Check that all locales has been handled
                        if (empty($locales)) {
                            break 2;
                        }
                    }
                }
            }

            if (!empty($redirections)) {
                foreach ($redirections as $locale => $redirection) {
                    if (!(array_key_exists('from', $redirection) && array_key_exists('to', $redirection))) {
                        continue;
                    }
                    // TODO use url generator or i18n routing prefix strategy
                    $localePrefix = $locale != 'fr' ? '/' . $locale : '';
                    $event = new BuildRedirectionEvent($localePrefix . $redirection['from'], $localePrefix . $redirection['to'], true);
                    $this->dispatcher->dispatch(RedirectionEvents::BUILD, $event);
                }
            }
        }
    }
921626
public function update(PageRequest $request, Model $page)
    {
        $page->update($request->all());
        return redirect()->route('admin.page.index');
    }
1017894
public function save(PageInterface $page)
    {
        if (!$page->getId() && !$page->getContentRoute()->getTemplateName()) {
            $page->setContentRoute(new ContentRoute());
        }
        $this->_em->persist($page);
    }
45349
public function update(Page $page)
    {
        $attributes = request()->validate(Page::$rules, Page::$messages);

        $attributes['is_header'] = boolval(input('is_header'));
        $attributes['is_hidden'] = boolval(input('is_hidden'));
        $attributes['is_footer'] = boolval(input('is_footer'));
        $attributes['is_featured'] = boolval(input('is_featured'));

        $page = $this->updateEntry($page, $attributes);
        $page->updateUrl()->save();
        $page->banners()->sync(input('banners'));

        return redirect_to_resource();
    }
1176144
public function getRedirect(Request $request, PageInterface $page)
    {
        if (method_exists($page, 'getAlias') && $page instanceof PageInterface) {
            if ($alias = $page->getAlias()) {
                $alias->getFullPath();
                $baseUrl = $request->getBaseUrl();

                $route = ContentRouteManager::generateRoute($alias->getContentRoute(), $alias->getFullPath(), '');

                return new RedirectResponse($baseUrl.$route->getPath());
            }
        }

        return false;
    }
41160
public function deactivatePage(Page $page)
    {

        if (!$this->isActive($page)) {
            return;
        }
        $this->deactivatePageId($page->getID());


    }
1259002
public function render($template, PageInterface $page = null)
    {
        if (!$template) {
            return null;
        }

        $twigTemplate = $this->twig->createTemplate($template);

        return $twigTemplate->render([
            'node' => $page,
        ]);
    }
761960
public function getDraftParameters(Request $request, PageInterface $page)
    {
        if ($redirect = $this->getRedirect($request, $page)) {
            return $redirect;
        }

        if ($page->getVisibility() != PageInterface::VISIBILITY_PUBLIC) {
            if (false === $this->get('security.authorization_checker')->isGranted('ROLE_USER')) {
                throw new AccessDeniedException();
            }
        }

        if ($page->getStatus() != PageInterface::STATUS_PUBLISHED) {
            if (!$this->get('security.token_storage')->getToken() || false === $this->get('security.authorization_checker')->isGranted(
                    'ROLE_SONATA_ADMIN'
                )
            ) {
                $message = 'The requested page has the status "'.$page->getStatus().'", please login to view page';
                throw $this->createNotFoundException($message);
            }
        }

        return ['page' => $page, 'admin_pool' => $this->getAdminPool()];
    }
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);
            }
        }*/
    }
495889
public function render(PageInterface $page)
    {
        $templateName = $this->locateTemplate();

        return $this
            ->engine
            ->render(
                $templateName, [
                    'page' => $page,
                ]
            );
    }
178066
public function dispatch(ServerRequestInterface $request)
    {
        parse_str($request->getUri()->getQuery(), $args);
        $uri = '/';
        if (isset($args['page'])) {
            $uri .= $args['page'];
        }

        return $this->createDispatcher()->dispatch(
            $request->getMethod(),
            $uri
        );
    }
15736
public function visitPage(PageInterface $page)
    {
        $template = 'page/' . $page->getType() . '.twig';

        return $this
            ->loadTemplate($template)
            ->render(
                [
                    "id" => $page->getId(),
                    "classes" => $page->getClasses(),
                    "data" => $page->getData(),
                    "title" => $page->getTitle(),
                    "baseHref" => $page->getBaseHref(),
                    "writables" => $page->getWritables(),
                    "projectCSS" => Settings::getInstance()->getProjectCSS(),
                    "projectJS" => Settings::getInstance()->getProjectJS(),
                ]
            );
    }
393663
public function set(): PageInterface
    {
        $hook = $this->isNetwork() ? 'network_admin_menu' : 'admin_menu';

        // Action for page display.
        $this->action->add($hook, [$this, 'build']);
        // Action for page settings.
        $this->action->add('admin_init', [$this, 'configureSettings']);

        return $this;
    }
705043
public function setPage($page)
    {
        $this->page = intval($page);
        
        if ($this->page == 0) {
            $this->page = 1;
        }
    }
1302496
public function handleForm(FormPageInterface $page, Request $request, RenderContext $context)
    {
        /* @var $em EntityManager */
        $em = $this->container->get('doctrine.orm.entity_manager');
        /* @var $formBuilder FormBuilderInterface */
        $formBuilder = $this->container->get('form.factory')->createBuilder(FormType::class);
        /* @var $router RouterInterface */
        $router = $this->container->get('router');
        /* @var $fields ArrayObject */
        $fields = new ArrayObject();
        $pageParts = $em->getRepository('KunstmaanPagePartBundle:PagePartRef')->getPageParts($page, $page->getFormElementsContext());
        foreach ($pageParts as $sequence => $pagePart) {
            if ($pagePart instanceof FormAdaptorInterface) {
                $pagePart->adaptForm($formBuilder, $fields, $sequence);
            }
        }

        $form = $formBuilder->getForm();
        if ($request->getMethod() == 'POST') {
            $form->handleRequest($request);
            if ($form->isSubmitted() && $form->isValid()) {
                $formSubmission = new FormSubmission();
                $formSubmission->setIpAddress($request->getClientIp());
                $formSubmission->setNode($em->getRepository('KunstmaanNodeBundle:Node')->getNodeFor($page));
                $formSubmission->setLang($request->getLocale());
                $em->persist($formSubmission);

                /* @var $field FormSubmissionField */
                foreach ($fields as $field) {
                    $field->setSubmission($formSubmission);
                    $field->onValidPost($form, $formBuilder, $request, $this->container);
                    $em->persist($field);
                }

                $em->flush();
                $em->refresh($formSubmission);

                $event = new SubmissionEvent($formSubmission, $page);
                $this->container->get('event_dispatcher')->dispatch(FormEvents::ADD_SUBMISSION, $event);

                return new RedirectResponse($page->generateThankYouUrl($router, $context));
            }
        }
        $context['frontendform'] = $form->createView();
        $context['frontendformobject'] = $form;

        return null;
    }
737202
public function page(int $page)
    {
        $this->query = array_merge($this->query ?? [], ['page' => $page]);

        return $this;
    }
1283117
private function renderPage(PageInterface $page)
    {
        if ($this->pageRenderer && $this->pageRenderer->supports($page)) {
            return $this
                ->pageRenderer
                ->render($page);
        }

        return $page->getContent();
    }