/** * 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()]); } }
/** * {@inheritdoc} */ public function getType() { $document = $this->getDocument(); $localizationState = $this->inspector->getLocalizationState($document); if ($localizationState === LocalizationState::GHOST) { return StructureType::getGhost($this->getDocument()->getLocale()); } if ($this->inspector->getLocalizationState($document) === LocalizationState::SHADOW) { return StructureType::getShadow($this->getDocument()->getLocale()); } }
/** * {@inheritdoc} */ public function handleHydrate(AbstractMappingEvent $event) { $document = $event->getDocument(); if (!$this->supportsBehavior($document)) { return; } $node = $event->getNode(); $propertyName = $this->getStructureTypePropertyName($document, $event->getLocale()); $structureType = $node->getPropertyValueWithDefault($propertyName, null); $rehydrate = $event->getOption('rehydrate'); if (!$structureType && $rehydrate) { $structureType = $this->getDefaultStructureType($document); } $document->setStructureType($structureType); if (false === $event->getOption('load_ghost_content', false)) { if ($this->inspector->getLocalizationState($document) === LocalizationState::GHOST) { $structureType = null; } } $container = $this->getStructure($document, $structureType, $rehydrate); // Set the property container $event->getAccessor()->set('structure', $container); }
/** * {@inheritdoc} */ public function handleHydrate(AbstractMappingEvent $event) { $document = $event->getDocument(); if (!$document instanceof StructureBehavior) { return; } $node = $event->getNode(); $propertyName = $this->getStructureTypePropertyName($document, $event->getLocale()); $value = $node->getPropertyValueWithDefault($propertyName, null); $document->setStructureType($value); if (false === $event->getOption('load_ghost_content', false)) { if ($this->inspector->getLocalizationState($document) === LocalizationState::GHOST) { $value = null; } } if ($value) { $container = $this->createStructure($document); } else { $container = new Structure(); } // Set the property container $event->getAccessor()->set('structure', $container); }
private function optionsShouldExcludeDocument($document, array $options = null) { if ($options === null) { return false; } $options = array_merge(array('exclude_ghost' => true, 'exclude_shadow' => true), $options); $state = $this->inspector->getLocalizationState($document); if ($options['exclude_ghost'] && $state == LocalizationState::GHOST) { return true; } if ($options['exclude_ghost'] && $options['exclude_shadow'] && $state == LocalizationState::SHADOW) { return true; } return false; }