Exemplo n.º 1
0
 /**
  * @param \Msingi\Cms\Entity\Page $page
  * @param string $language
  * @return \Msingi\Cms\Entity\PageI18n
  */
 public function fetchOrCreate($page, $language)
 {
     $i18n = $this->findOneBy(array('parent' => $page, 'language' => $language));
     if ($i18n == null) {
         $i18n = new PageI18n();
         $i18n->setParent($page);
         $i18n->setLanguage($language);
         $this->getEntityManager()->persist($i18n);
         $this->getEntityManager()->flush();
     }
     return $i18n;
 }
Exemplo n.º 2
0
 /**
  * @param string $name
  * @return string
  */
 public function __invoke($name)
 {
     if ($this->meta == null) {
         $serviceManager = $this->event->getApplication()->getServiceManager();
         $translator = $serviceManager->get('Translator');
         $locale = $translator->getLocale();
         /** @var \Msingi\Cms\Repository\PageI18ns $meta_repository */
         $meta_repository = $this->getEntityManager()->getRepository('Msingi\\Cms\\Entity\\PageI18n');
         $this->meta = $meta_repository->fetchOrCreate($this->page, \Locale::getPrimaryLanguage($locale));
     }
     switch ($name) {
         case 'title':
             return $this->meta->getTitle();
         case 'keywords':
             return $this->meta->getKeywords();
         case 'description':
             return $this->meta->getDescription();
     }
     return '';
 }