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

handleReorder() public method

Adjusts the order of the document and its siblings.
public handleReorder ( Sulu\Component\DocumentManager\Event\ReorderEvent $event )
$event Sulu\Component\DocumentManager\Event\ReorderEvent
    public function handleReorder(ReorderEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof OrderBehavior) {
            return;
        }
        $parentDocument = $this->documentInspector->getParent($document);
        if (null === $parentDocument) {
            return;
        }
        $count = 1;
        foreach ($this->documentInspector->getChildren($parentDocument) as $childDocument) {
            if (!$childDocument instanceof OrderBehavior) {
                continue;
            }
            $order = $count * 10;
            $childDocument->setSuluOrder($order);
            // TODO move to NodeHelper once integrated in sulu/sulu?
            $childNode = $this->documentInspector->getNode($childDocument);
            $childNode->setProperty($this->propertyEncoder->systemName(static::FIELD), $order);
            ++$count;
        }
    }

Usage Example

示例#1
0
 /**
  * It should return early on REORDER if the document has no parent (i.e. if the document is the root document and this shoouldn't really happen).
  */
 public function testReorderNoParent()
 {
     $document = $this->prophesize(OrderBehavior::class);
     $reorderEvent = $this->prophesize(ReorderEvent::class);
     $reorderEvent->getDocument()->willReturn($document->reveal());
     $this->inspector->getParent($document->reveal())->willReturn(null);
     $this->subscriber->handleReorder($reorderEvent->reveal());
     $this->inspector->getChildren(Argument::any())->shouldNotHaveBeenCalled();
 }
All Usage Examples Of Sulu\Component\Content\Document\Subscriber\OrderSubscriber::handleReorder