/**
  * It should set the default locale.
  */
 public function testDefaultLocale()
 {
     $this->hydrateEvent->getLocale()->willReturn(null);
     $this->registry->getDefaultLocale()->willReturn('de');
     $this->hydrateEvent->setLocale('de')->shouldBeCalled();
     $this->subscriber->handleDefaultLocale($this->hydrateEvent->reveal());
 }
 /**
  * Set the default locale for the hydration request.
  *
  * @param HydrateEvent $event
  */
 public function handleDefaultLocale(HydrateEvent $event)
 {
     // set the default locale
     if (null === $event->getLocale()) {
         $event->setLocale($this->documentRegistry->getDefaultLocale());
     }
 }
예제 #3
0
 /**
  * @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);
 }