/** * 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); }
/** * It should not register on PERSIST when there is already a document. */ public function testHandleRegisterPersistAlreadyExists() { $this->persistEvent->getDocument()->willReturn($this->document); $this->persistEvent->getNode()->willReturn($this->node->reveal()); $this->persistEvent->getLocale()->willReturn('fr'); $this->registry->registerDocument($this->document, $this->node->reveal(), 'fr')->shouldNotBeCalled(); $this->registry->updateLocale($this->document, 'fr')->shouldBeCalled(); $this->registry->hasDocument($this->document)->willReturn(true); $this->subscriber->handlePersist($this->persistEvent->reveal()); }
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); }
/** * @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); }
/** * It should return any localizations if neither parent nor children. */ public function testWebspaceAnyLocalization() { $this->inspector->getWebspace($this->document->reveal())->willReturn(self::FIX_WEBSPACE); $this->inspector->getLocales($this->document->reveal())->willReturn(['de']); $this->webspace->getLocalization(self::FIX_LOCALE)->willReturn($this->localization1->reveal()); $this->localization1->getLocalization()->willReturn('en'); $this->localization2->getLocalization()->willReturn('de'); $this->hydrateEvent->getOption('load_ghost_content', true)->willReturn(true); $this->localization1->getParent()->willReturn(null); $this->localization1->getChildren()->willReturn([]); $this->webspace->getLocalizations()->willReturn([$this->localization2->reveal()]); $this->registry->updateLocale($this->document->reveal(), 'de', 'en')->shouldBeCalled(); $this->hydrateEvent->setLocale('de')->shouldBeCalled(); $this->subscriber->handleHydrate($this->hydrateEvent->reveal()); }