Sulu\Bundle\DocumentManagerBundle\Bridge\DocumentInspector::getContentPath PHP Method

getContentPath() public method

TODO: We need a better solution for retrieving webspace paths (the existing "session manager" is not a good solution).
public getContentPath ( Sulu\Component\DocumentManager\Behavior\Mapping\PathBehavior $document ) : string
$document Sulu\Component\DocumentManager\Behavior\Mapping\PathBehavior
return string
    public function getContentPath(PathBehavior $document)
    {
        $path = $this->getPath($document);
        $webspaceKey = $this->getWebspace($document);
        return str_replace(sprintf('/%s/%s/%s', $this->pathSegmentRegistry->getPathSegment('base'), $webspaceKey, $this->pathSegmentRegistry->getPathSegment('content')), '', $path);
    }

Usage Example

Example #1
0
 /**
  * Adds the relative path to the serialization.
  *
  * @param ObjectEvent $event
  */
 public function onPostSerialize(ObjectEvent $event)
 {
     $visitor = $event->getVisitor();
     $document = $event->getObject();
     if (!$document instanceof PathBehavior || !$this->documentRegistry->hasDocument($document)) {
         return;
     }
     $visitor->addData('path', $this->documentInspector->getContentPath($document));
 }
All Usage Examples Of Sulu\Bundle\DocumentManagerBundle\Bridge\DocumentInspector::getContentPath