コード例 #1
0
 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);
 }
コード例 #2
0
 /**
  * @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);
 }
コード例 #3
0
ファイル: OrderSubscriber.php プロジェクト: Silwereth/sulu
 /**
  * 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);
 }
コード例 #4
0
ファイル: BlameSubscriber.php プロジェクト: sulu/sulu
 /**
  * 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);
 }
コード例 #5
0
 /**
  * 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);
 }