/** * Updates the SEO page values for given page instance * * @param PageInterface $page */ protected function updateSeoPage(PageInterface $page, $locale) { /** * @var LanguageVersion $languageVersion */ $languageVersion = $page->getSite()->getLanguageVersion($locale); $siteTitle = $languageVersion->getTitle() ?: $page->getSite()->getName(); if (!$page->getParent()) { $title = $siteTitle; } else { if ($page->getTitle()) { $title = $page->getTitle() . ' - ' . $siteTitle; } elseif ($page->getName()) { $title = $page->getName() . ' - ' . $siteTitle; } } $this->seoPage->setTitle($title); $this->seoPage->addMeta('property', 'og:title', $title); if ($page->getMetaDescription()) { $this->seoPage->addMeta('name', 'description', $page->getMetaDescription()); $this->seoPage->addMeta('property', 'og:description', $page->getMetaDescription()); } elseif ($languageVersion->getMetaDescription()) { $this->seoPage->addMeta('name', 'description', $languageVersion->getMetaDescription()); $this->seoPage->addMeta('property', 'og:description', $languageVersion->getMetaDescription()); } if ($page->getMetaKeyword()) { $this->seoPage->addMeta('name', 'keywords', $page->getMetaKeyword()); } elseif ($languageVersion->getMetaKeywords()) { $this->seoPage->addMeta('name', 'keywords', $languageVersion->getMetaKeywords()); } $this->seoPage->addMeta('property', 'og:site_name', $languageVersion->getTitle()); $this->seoPage->addMeta('property', 'og:url', 'http://' . $languageVersion->getHost() . $languageVersion->getRelativePath()); $this->seoPage->addMeta('property', 'og:type', 'website'); $this->seoPage->addHtmlAttributes('prefix', 'og: http://ogp.me/ns#'); }
/** * Updates the SEO page values for given page instance * * @param PageInterface $page */ protected function updateSeoPage(PageInterface $page, Request $request) { /** * @var LanguageVersion $languageVersion */ $languageVersion = $page->getSite()->getLanguageVersion($request->getLocale()); $siteTitle = $languageVersion->getTitle() ?: $page->getSite()->getName(); if (!$page->getParent()) { $title = $siteTitle; } else { if ($page->getTitle()) { $title = $page->getTitle() . ' - ' . $siteTitle; } elseif ($page->getName()) { $title = $page->getName() . ' - ' . $siteTitle; } else { $title = $siteTitle; } } $this->seoPage->setTitle($title); $this->seoPage->addMeta('property', 'og:title', $title); if ($page->getMetaDescription()) { $this->seoPage->addMeta('name', 'description', $page->getMetaDescription()); $this->seoPage->addMeta('property', 'og:description', $page->getMetaDescription()); } elseif ($languageVersion->getMetaDescription()) { $this->seoPage->addMeta('name', 'description', $languageVersion->getMetaDescription()); $this->seoPage->addMeta('property', 'og:description', $languageVersion->getMetaDescription()); } if ($page->getMetaKeyword()) { $this->seoPage->addMeta('name', 'keywords', $page->getMetaKeyword()); } elseif ($languageVersion->getMetaKeywords()) { $this->seoPage->addMeta('name', 'keywords', $languageVersion->getMetaKeywords()); } if ($page->getOgImage()) { //$ogImageUrl = $this->get('sonata.media.twig.extension')->path($ogImage, 'og_image'); TODO $this->seoPage->addMeta('property', 'og:image', strpos($page->getOgImage(), '://') !== false ? $page->getOgImage() : sprintf('%s://%s%s', isset($_SERVER['HTTPS']) ? 'https' : 'http', $_SERVER['HTTP_HOST'], $page->getOgImage())); } $this->seoPage->addMeta('property', 'og:site_name', $languageVersion->getTitle()); $this->seoPage->addMeta('property', 'og:url', $request->getUri()); $this->seoPage->addMeta('property', 'og:type', 'website'); $this->seoPage->addHtmlAttributes('prefix', 'og: http://ogp.me/ns#'); }
public function iterate($menu, PageInterface $page) { foreach ($page->getChildren() as $page) { if ($page->isHybrid() || !$page->getUrl()) { continue; } $menu->addChild($page->getName(), array('route' => $page->getRouteName(), 'routeParameters' => array('path' => $page->getUrl()))); if ($page->getChildren()) { $this->iterate($menu[$page->getName()], $page); } } }
/** * Updates the SEO page values for given page instance. * * @param PageInterface $page */ protected function updateSeoPage(PageInterface $page) { if (!$this->seoPage) { return; } $this->seoPage->setTitle($page->getTitle() ?: $page->getName()); if ($page->getMetaDescription()) { $this->seoPage->addMeta('name', 'description', $page->getMetaDescription()); } if ($page->getMetaKeyword()) { $this->seoPage->addMeta('name', 'keywords', $page->getMetaKeyword()); } $this->seoPage->addMeta('property', 'og:type', 'article'); $this->seoPage->addHtmlAttributes('prefix', 'og: http://ogp.me/ns#'); }
/** * {@inheritdoc} */ 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 (substr($page->getParent()->getUrl(), -1) != '/') { $base = $page->getParent()->getUrl() . '/'; } else { $base = $page->getParent()->getUrl(); } $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); } }
public function fixUrl(PageInterface $page) { // hybrid page cannot be altered if (!$page->isHybrid()) { if (!$page->getSlug()) { $page->setSlug(Page::slugify($page->getName())); } // make sure Page has a valid url if ($page->getParent()) { $base = $page->getParent()->getUrl() == '/' ? '/' : $page->getParent()->getUrl() . '/'; $page->setUrl($base . $page->getSlug()); } else { $page->setUrl('/' . $page->getSlug()); } } foreach ($page->getChildren() as $child) { $this->fixUrl($child); } }