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);
                }
            }
        }
    }
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);
                }
            }
        }
    }
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 ) ; } } } }
Builds redirections for the page.

@param PageInterface $page
Builds redirections for the page .