vendor/sulu/sulu/src/Sulu/Component/Content/Document/Subscriber/StructureTypeFilingSubscriber.php line 22

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Component\Content\Document\Subscriber;
  11. use Sulu\Component\Content\Document\Behavior\StructureTypeFilingBehavior;
  12. use Sulu\Component\DocumentManager\Event\PersistEvent;
  13. use Sulu\Component\DocumentManager\Events;
  14. use Sulu\Component\DocumentManager\Subscriber\Behavior\Path\AbstractFilingSubscriber;
  15. /**
  16.  * Automatically set the parent at a pre-determined location.
  17.  */
  18. class StructureTypeFilingSubscriber extends AbstractFilingSubscriber
  19. {
  20.     public static function getSubscribedEvents()
  21.     {
  22.         return [
  23.             Events::PERSIST => ['handlePersist'485],
  24.         ];
  25.     }
  26.     protected function generatePath(PersistEvent $event)
  27.     {
  28.         $document $event->getDocument();
  29.         $currentPath '';
  30.         if ($event->hasParentNode()) {
  31.             $currentPath $event->getParentNode()->getPath();
  32.         }
  33.         $parentName $this->getParentName($document);
  34.         return \sprintf('%s/%s'$currentPath$parentName);
  35.     }
  36.     protected function supports($document)
  37.     {
  38.         return $document instanceof StructureTypeFilingBehavior;
  39.     }
  40.     protected function getParentName($document)
  41.     {
  42.         return $document->getStructureType();
  43.     }
  44. }