Sulu\Component\Content\Document\Subscriber\OrderSubscriber::handlePersist PHP Method

handlePersist() public method

Adjusts the order of the document and its siblings.
public handlePersist ( Sulu\Component\DocumentManager\Event\PersistEvent $event )
$event Sulu\Component\DocumentManager\Event\PersistEvent
    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;
        $document->setSuluOrder($order);
    }

Usage Example

示例#1
0
 /**
  * It should set the order on the document.
  */
 public function testPersistOrder()
 {
     $this->node->getParent()->willReturn($this->parentNode->reveal());
     $this->parentNode->getNodes()->willReturn([$this->node->reveal()]);
     $this->persistEvent->getAccessor()->willReturn($this->accessor->reveal());
     $this->accessor->set('suluOrder', 20)->shouldBeCalled();
     $this->subscriber->handlePersist($this->persistEvent->reveal());
 }
All Usage Examples Of Sulu\Component\Content\Document\Subscriber\OrderSubscriber::handlePersist