/** * @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); }