/**
  * It should not register documents on the HYDRATE event when there is already a document.
  */
 public function testHandleRegisterHydrateAlreadyExisting()
 {
     $this->hydrateEvent->getDocument()->willReturn($this->document);
     $this->hydrateEvent->getNode()->willReturn($this->node->reveal());
     $this->hydrateEvent->getLocale()->willReturn('fr');
     $this->registry->hasDocument($this->document)->willReturn(true);
     $this->registry->registerDocument($this->document, $this->node->reveal(), 'fr')->shouldNotBeCalled();
     $this->registry->updateLocale($this->document, 'fr')->shouldBeCalled();
     $this->subscriber->handleHydrate($this->hydrateEvent->reveal());
 }
 /**
  * @param HydrateEvent $event
  */
 public function handleHydrate(HydrateEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof TimestampBehavior) {
         return;
     }
     $node = $event->getNode();
     $locale = $event->getLocale();
     $accessor = $event->getAccessor();
     $accessor->set(self::CREATED, $node->getPropertyValueWithDefault($v = $this->encoder->localizedSystemName(self::CREATED, $locale), null));
     $accessor->set(self::CHANGED, $node->getPropertyValueWithDefault($this->encoder->localizedSystemName(self::CHANGED, $locale), null));
 }
 /**
  * Stop propagation if the document is already loaded in the requested locale,
  * otherwise reset the document locale to the new locale.
  *
  * @param HydrateEvent $event
  */
 public function handleStopPropagationAndResetLocale(HydrateEvent $event)
 {
     if (!$event->hasDocument()) {
         return;
     }
     $locale = $event->getLocale();
     $document = $event->getDocument();
     $originalLocale = $this->documentRegistry->getOriginalLocaleForDocument($document);
     if (true === $this->documentRegistry->isHydrated($document) && $originalLocale === $locale) {
         $event->stopPropagation();
         return;
     }
     $this->documentRegistry->updateLocale($document, $locale, $locale);
 }
 /**
  * @param HydrateEvent $event
  */
 public function handleHydrate(HydrateEvent $event)
 {
     $document = $event->getDocument();
     // we currently only support fallback on StructureBehavior implementors
     // because we use the template key to determine localization status
     if (!$document instanceof StructureBehavior) {
         return;
     }
     $locale = $event->getLocale();
     if (!$locale || false === $event->getOption('load_ghost_content', true)) {
         return;
     }
     // change locale of document of ghost content should be loaded
     $newLocale = $this->getAvailableLocalization($document, $locale);
     $event->setLocale($newLocale);
     $document->setLocale($newLocale);
 }
 /**
  * @param HydrateEvent $event
  */
 public function handleHydrate(HydrateEvent $event)
 {
     $document = $event->getDocument();
     // we currently only support fallback on StructureBehavior implementors
     // because we use the template key to determine localization status
     if (!$document instanceof StructureBehavior) {
         return;
     }
     $locale = $event->getLocale();
     if (!$locale) {
         return;
     }
     $newLocale = $this->getAvailableLocalization($document, $locale);
     $event->setLocale($newLocale);
     if ($newLocale === $locale) {
         return;
     }
     if ($event->getOption('load_ghost_content', true) === true) {
         $this->documentRegistry->updateLocale($document, $newLocale, $locale);
         return;
     }
     $this->documentRegistry->updateLocale($document, $locale, $locale);
 }
示例#6
0
 /**
  * Determines if the given document is supported by this subscriber.
  *
  * @param HydrateEvent|PublishEvent|PersistEvent $event
  *
  * @return bool
  */
 private function supports($event)
 {
     return $event->getLocale() && $event->getDocument() instanceof WorkflowStageBehavior;
 }