public function setUp() { $this->persistEvent = $this->prophesize(PersistEvent::class); $this->hydrateEvent = $this->prophesize(HydrateEvent::class); $this->notImplementing = new \stdClass(); $this->encoder = $this->prophesize(PropertyEncoder::class); $this->node = $this->prophesize(NodeInterface::class); $this->accessor = $this->prophesize(DocumentAccessor::class); $this->persistEvent->getNode()->willReturn($this->node); $this->persistEvent->getAccessor()->willReturn($this->accessor); $this->hydrateEvent->getAccessor()->willReturn($this->accessor); }
/** * @param PersistEvent $event */ public function handlePersist(PersistEvent $event) { $locale = $event->getLocale(); if (!$locale) { return; } $document = $event->getDocument(); if (!$document instanceof WorkflowStageBehavior) { return; } $stage = $document->getWorkflowStage(); $node = $event->getNode(); $persistedStage = $this->getWorkflowStage($node, $locale); if ($stage == WorkflowStage::PUBLISHED && $stage !== $persistedStage) { $event->getAccessor()->set(self::PUBLISHED_FIELD, new \DateTime()); } if ($stage == WorkflowStage::TEST && $stage !== $persistedStage) { $event->getAccessor()->set(self::PUBLISHED_FIELD, null); } $document->setWorkflowStage($stage); }
/** * Adjusts the order of the document and its siblings. * * @param PersistEvent $event */ public function handlePersist(PersistEvent $event) { $document = $event->getDocument(); if (false == $document instanceof OrderBehavior) { return; } if ($document->getSuluOrder()) { return; } $node = $event->getNode(); $parent = $node->getParent(); $nodeCount = count($parent->getNodes()); $order = ($nodeCount + 1) * 10; $event->getAccessor()->set('suluOrder', $order); }
/** * Persists the data of creator and changer to the Node. * * @param PersistEvent $event */ public function handlePersist(PersistEvent $event) { $document = $event->getDocument(); if (!$document instanceof LocalizedBlameBehavior) { return; } $userId = $this->getUserId($event->getOptions()); if (null === $userId) { return; } if (!$event->getLocale()) { return; } if (!$document->getCreator()) { $event->getAccessor()->set(self::CREATOR, $userId); } $event->getAccessor()->set(self::CHANGER, $userId); }
/** * If this is a shadow document, update the URL to that of the shadowed document. * * TODO: This is about caching and should be handled somewhere else. * * @param PersistEvent $event */ public function handlePersistUpdateUrl(PersistEvent $event) { $document = $event->getDocument(); if (!$this->supports($document)) { return; } if (!$document->isShadowLocaleEnabled()) { return; } $node = $event->getNode(); $structure = $this->inspector->getStructureMetadata($document); if (false === $structure->hasPropertyWithTagName('sulu.rlp')) { return; } $locatorProperty = $structure->getPropertyByTagName('sulu.rlp'); if ($node->getPropertyValueWithDefault($this->encoder->localizedSystemName($locatorProperty->getName(), $document->getLocale()), null)) { return; } $shadowLocator = $node->getPropertyValueWithDefault($this->encoder->localizedSystemName($locatorProperty->getName(), $document->getShadowLocale()), null); if (!$shadowLocator) { return; } $event->getAccessor()->set('resourceSegment', $shadowLocator); }