/** * Adds the relative path to the serialization. * * @param ObjectEvent $event */ public function onPostSerialize(ObjectEvent $event) { $visitor = $event->getVisitor(); $document = $event->getObject(); if (!$document instanceof PathBehavior || !$this->documentRegistry->hasDocument($document)) { return; } $visitor->addData('path', $this->documentInspector->getContentPath($document)); }
/** * Adds the enabled shadow languages to the serialization. * * @param ObjectEvent $event */ public function onPostSerialize(ObjectEvent $event) { $document = $event->getObject(); if (!$document instanceof ShadowLocaleBehavior || !$this->documentRegistry->hasDocument($document)) { return; } $visitor = $event->getVisitor(); $visitor->addData('enabledShadowLanguages', $this->documentInspector->getShadowLocales($document)); }
/** * Adds a flag to indicate if the document has children. * * @param ObjectEvent $event */ public function onPostSerialize(ObjectEvent $event) { $document = $event->getObject(); if (!$document instanceof ChildrenBehavior || !$this->documentRegistry->hasDocument($document)) { return; } $visitor = $event->getVisitor(); $visitor->addData('hasSub', $this->documentInspector->hasChildren($document)); }
/** * Adds the concrete languages available and the type (ghost or shadow) of the document to the serialization. * * @param ObjectEvent $event */ public function onPostSerialize(ObjectEvent $event) { $document = $event->getObject(); if (!$document instanceof LocaleBehavior || !$this->documentRegistry->hasDocument($document)) { return; } $visitor = $event->getVisitor(); $visitor->addData('concreteLanguages', $this->documentInspector->getConcreteLocales($document)); $localizationState = $this->documentInspector->getLocalizationState($document); if ($localizationState === LocalizationState::GHOST) { $visitor->addData('type', ['name' => 'ghost', 'value' => $document->getLocale()]); } if ($localizationState === LocalizationState::SHADOW) { $visitor->addData('type', ['name' => 'shadow', 'value' => $document->getLocale()]); } }
/** * 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 ObjectEvent $event */ public function onPostDeserialize(ObjectEvent $event) { $document = $event->getObject(); // only register documents if (!$this->metadataFactory->hasMetadataForClass(get_class($document))) { return; } if (!$document->getUuid()) { return; } try { $node = $this->nodeManager->find($document->getUuid()); } catch (DocumentNotFoundException $e) { return; } if ($this->registry->hasNode($node, $document->getLocale())) { $registeredDocument = $this->registry->getDocumentForNode($node, $document->getLocale()); $this->registry->deregisterDocument($registeredDocument); } // TODO use the original locale somehow if (!$this->registry->hasDocument($document)) { $this->registry->registerDocument($document, $node, $document->getLocale()); } }