Exemple #1
0
 /**
  * Sets the title on the node from the value in the document.
  *
  * @param PersistEvent $event
  */
 public function setTitleOnNode(AbstractMappingEvent $event)
 {
     $document = $event->getDocument();
     if (!$this->supports($document)) {
         return;
     }
     if ($document instanceof LocalizedTitleBehavior) {
         if (!$event->getLocale()) {
             return;
         }
         $event->getNode()->setProperty($this->propertyEncoder->localizedContentName(static::PROPERTY_NAME, $event->getLocale()), $document->getTitle());
     } else {
         $event->getNode()->setProperty($this->propertyEncoder->contentName(static::PROPERTY_NAME), $document->getTitle());
     }
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function saveExtensionData(AbstractMappingEvent $event)
 {
     $locale = $event->getLocale();
     if (!$locale) {
         return;
     }
     $document = $event->getDocument();
     if (!$document instanceof ExtensionBehavior) {
         return;
     }
     $structureType = $document->getStructureType();
     $node = $event->getNode();
     $extensionsData = $document->getExtensionsData();
     $webspaceName = $this->inspector->getWebspace($document);
     $prefix = $this->namespaceRegistry->getPrefix('extension_localized');
     $extensions = $this->extensionManager->getExtensions($structureType);
     foreach ($extensions as $extension) {
         $extensionData = null;
         if (!isset($extensionsData[$extension->getName()])) {
             continue;
         }
         $extensionData = $extensionsData[$extension->getName()];
         $extension->setLanguageCode($locale, $prefix, $this->internalPrefix);
         $extension->save($node, $extensionData, $webspaceName, $locale);
     }
     $this->hydrate($event);
 }
 /**
  * @param AbstractMappingEvent $event
  */
 public function doHydrate(AbstractMappingEvent $event)
 {
     $node = $event->getNode();
     $document = $event->getDocument();
     $redirectType = $node->getPropertyValueWithDefault($this->encoder->localizedSystemName(self::REDIRECT_TYPE_FIELD, $event->getLocale()), RedirectType::NONE);
     $document->setRedirectType($redirectType);
     if ($redirectType === RedirectType::INTERNAL) {
         $internalNode = $node->getPropertyValueWithDefault($this->encoder->localizedSystemName(self::INTERNAL_FIELD, $event->getLocale()), null);
         if ($internalNode) {
             $document->setRedirectTarget($this->proxyFactory->createProxyForNode($document, $internalNode));
         }
     }
     if ($redirectType === RedirectType::EXTERNAL) {
         $externalUrl = $node->getPropertyValueWithDefault($this->encoder->localizedSystemName(self::EXTERNAL_FIELD, $event->getLocale()), null);
         $document->setRedirectExternal($externalUrl);
     }
 }
 /**
  * Update the locale to the shadow locale, if it is enabled.
  *
  * Note that this should happen before the fallback locale has been resolved
  *
  * @param HydrateEvent $event
  */
 public function doHydrate(AbstractMappingEvent $event)
 {
     $node = $event->getNode();
     $locale = $event->getLocale();
     $document = $event->getDocument();
     $shadowLocaleEnabled = $this->getShadowLocaleEnabled($node, $locale);
     $document->setShadowLocaleEnabled($shadowLocaleEnabled);
     if (!$shadowLocaleEnabled) {
         return;
     }
     $document->setShadowLocale($this->getShadowLocale($node, $locale));
     $shadowLocale = $this->getShadowLocale($node, $locale);
     $this->registry->updateLocale($document, $shadowLocale, $locale);
     $event->setLocale($shadowLocale);
 }
 /**
  * Update the locale to the shadow locale, if it is enabled.
  *
  * Note that this should happen before the fallback locale has been resolved
  *
  * @param AbstractMappingEvent $event
  */
 public function handleHydrate(AbstractMappingEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof ShadowLocaleBehavior) {
         return;
     }
     $node = $event->getNode();
     $locale = $event->getLocale();
     $shadowLocaleEnabled = $this->getShadowLocaleEnabled($node, $locale);
     $document->setShadowLocaleEnabled($shadowLocaleEnabled);
     if (!$shadowLocaleEnabled) {
         return;
     }
     $shadowLocale = $this->getShadowLocale($node, $locale);
     $document->setShadowLocale($shadowLocale);
     $this->registry->updateLocale($document, $shadowLocale, $locale);
     $event->setLocale($shadowLocale);
 }
 private function handleRegister(AbstractMappingEvent $event)
 {
     $document = $event->getDocument();
     $node = $event->getNode();
     $locale = $event->getLocale();
     if ($this->documentRegistry->hasDocument($document)) {
         $this->documentRegistry->updateLocale($document, $locale);
         return;
     }
     $this->documentRegistry->registerDocument($document, $node, $locale);
 }
Exemple #7
0
 /**
  * {@inheritdoc}
  */
 public function saveStructureData(AbstractMappingEvent $event)
 {
     // Set the structure type
     $document = $event->getDocument();
     if (!$this->supportsBehavior($document)) {
         return;
     }
     if (!$document->getStructureType()) {
         return;
     }
     if (!$event->getLocale()) {
         return;
     }
     $node = $event->getNode();
     $locale = $event->getLocale();
     $options = $event->getOptions();
     $this->mapContentToNode($document, $node, $locale, $options['ignore_required']);
     $node->setProperty($this->getStructureTypePropertyName($document, $locale), $document->getStructureType());
 }
Exemple #8
0
 /**
  * {@inheritdoc}
  */
 public function handleHydrate(AbstractMappingEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof StructureBehavior) {
         return;
     }
     $node = $event->getNode();
     $propertyName = $this->getStructureTypePropertyName($document, $event->getLocale());
     $value = $node->getPropertyValueWithDefault($propertyName, null);
     $document->setStructureType($value);
     if (false === $event->getOption('load_ghost_content', false)) {
         if ($this->inspector->getLocalizationState($document) === LocalizationState::GHOST) {
             $value = null;
         }
     }
     if ($value) {
         $container = $this->createStructure($document);
     } else {
         $container = new Structure();
     }
     // Set the property container
     $event->getAccessor()->set('structure', $container);
 }
Exemple #9
0
 /**
  * {@inheritdoc}
  */
 public function saveShadowProperties(AbstractMappingEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof ShadowLocaleBehavior) {
         return;
     }
     if (!$event->getLocale()) {
         return;
     }
     if ($document->isShadowLocaleEnabled()) {
         $this->validateShadow($document);
     }
     $event->getNode()->setProperty($this->encoder->localizedSystemName(self::SHADOW_ENABLED_FIELD, $event->getLocale()), $document->isShadowLocaleEnabled() ?: null);
     $event->getNode()->setProperty($this->encoder->localizedSystemName(self::SHADOW_LOCALE_FIELD, $event->getLocale()), $document->getShadowLocale());
 }
 /**
  * @param AbstractMappingEvent $event
  *
  * @throws DocumentManagerException
  */
 public function handleHydrate(AbstractMappingEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof BlameBehavior) {
         return;
     }
     $node = $event->getNode();
     $locale = $event->getLocale();
     $accessor = $event->getAccessor();
     $accessor->set(self::CREATOR, $this->getCreator($node, $locale));
     $accessor->set(self::CHANGER, $node->getPropertyValueWithDefault($this->encoder->localizedSystemName(self::CHANGER, $locale), null));
 }
 /**
  * @param HydrateEvent $event
  */
 public function doHydrate(AbstractMappingEvent $event)
 {
     $node = $event->getNode();
     $value = $node->getPropertyValueWithDefault($this->encoder->localizedSystemName(self::FIELD, $event->getLocale()), []);
     $event->getDocument()->setNavigationContexts($value);
 }