Ejemplo n.º 1
0
 /**
  * @param LocaleInterface $locale
  * @throws \InvalidArgumentException
  */
 public function addLocale(LocaleInterface $locale)
 {
     $id = $locale->getId();
     if (empty($id)) {
         throw new \InvalidArgumentException('Empty locale ID is not allowed.');
     }
     if ($this->hasLocale($id)) {
         throw new \InvalidArgumentException(sprintf('Locale [%s] is already defined.', $id));
     }
     $this->locales[$id] = $locale;
 }
Ejemplo n.º 2
0
 /**
  * Makes deep copy with persisting.
  *
  * @param Localization $source
  * @param LocaleInterface $targetLocale
  * @return Localization
  */
 public function copyLocalization(Localization $source, LocaleInterface $targetLocale)
 {
     $deepCopy = new DeepCopy();
     $entityManager = $this->container->getDoctrine()->getManagerForClass(get_class($source));
     // Matches Localization::$master.
     // Prevents AbstractPage to be cloned.
     $deepCopy->addFilter(new KeepFilter(), new PropertyMatcher(get_class($source), 'master'));
     $this->addDeepCopyCommonFilters($deepCopy, $entityManager);
     $copiedLocalization = $deepCopy->copy($source);
     $copiedLocalization->setLocaleId($targetLocale->getId());
     $entityManager->persist($copiedLocalization);
     return $copiedLocalization;
 }
Ejemplo n.º 3
0
 public static function getLinkReferencedElementUrl(LinkReferencedElement $element, EntityManager $entityManager, LocaleInterface $currenctLocale)
 {
     switch ($element->getResource()) {
         case LinkReferencedElement::RESOURCE_LINK:
             return $element->getHref();
         case LinkReferencedElement::RESOURCE_PAGE:
             $localization = $entityManager->getRepository(PageLocalization::CN())->findOneBy(array('master' => $element->getPageId(), 'locale' => $currenctLocale->getId()));
             /* @var $localization PageLocalization */
             if ($localization !== null) {
                 // @TODO: allow to affect the path somehow?
                 return $localization->getFullPath(Path::FORMAT_LEFT_DELIMITER);
             }
             break;
         case LinkReferencedElement::RESOURCE_FILE:
             // @FIXME: get the filestorage somehow, or use File entity?
             throw new \Exception('Implement me, I have no file storage here.');
             break;
         default:
             throw new \UnexpectedValueException("Unrecognized resource type [{$element->getResource()}].");
     }
     return null;
     // @TODO: 'email' resource type handling?
 }