/**
  * 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#');
 }
 /**
  * {@inheritdoc}
  */
 public function getBlocksById(PageInterface $page)
 {
     $query = $this->getEntityManager()->createQuery(sprintf('SELECT b FROM %s b INDEX BY b.id WHERE b.page = :page ORDER BY b.position ASC', $this->blockManager->getClass()))->setParameters(array('page' => $page->getId()));
     $query->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
     $query->setHint(\Gedmo\Translatable\TranslatableListener::HINT_TRANSLATABLE_LOCALE, $page->getSite()->getLocale());
     $blocks = $query->execute();
     $page->setBlocks(new ArrayCollection($blocks));
     return $blocks;
 }
 /**
  * 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#');
 }
 /**
  * {@inheritdoc}
  */
 public function getChildren(PageInterface $parent)
 {
     if (!isset($this->children[$parent->getId()])) {
         $date = new \Datetime();
         $parameters = array('publicationDateStart' => $date, 'publicationDateEnd' => $date, 'parentId' => $parent->getId());
         $manager = $this->registry->getManagerForClass($this->snapshotManager->getClass());
         if (!$manager instanceof EntityManagerInterface) {
             throw new \RuntimeException('Invalid entity manager type');
         }
         $snapshots_query = $manager->createQueryBuilder()->select('s')->from($this->snapshotManager->getClass(), 's')->where('s.parentId = :parentId and s.enabled = 1')->andWhere('s.publicationDateStart <= :publicationDateStart AND ( s.publicationDateEnd IS NULL OR s.publicationDateEnd >= :publicationDateEnd )')->orderBy('s.position')->setParameters($parameters)->getQuery();
         $snapshots_query->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
         $snapshots_query->setHint(\Gedmo\Translatable\TranslatableListener::HINT_TRANSLATABLE_LOCALE, $parent->getSite()->getLocale());
         $snapshots = $snapshots_query->execute();
         $pages = array();
         foreach ($snapshots as $snapshot) {
             $page = new SnapshotPageProxy($this->snapshotManager, $this, $snapshot);
             $pages[$page->getId()] = $page;
         }
         $this->children[$parent->getId()] = new \Doctrine\Common\Collections\ArrayCollection($pages);
     }
     return $this->children[$parent->getId()];
 }