Neos\ContentRepository\Domain\Utility\NodePaths::getParentPath PHP Method

getParentPath() public static method

Get the parent path of the given Node path.
public static getParentPath ( string $path ) : string
$path string
return string
    public static function getParentPath($path)
    {
        if ($path === '/') {
            $parentPath = '';
        } elseif (strrpos($path, '/') === 0) {
            $parentPath = '/';
        } else {
            $parentPath = substr($path, 0, strrpos($path, '/'));
        }
        return $parentPath;
    }

Usage Example

 /**
  * Sets the absolute path of this node
  *
  * @param string $path
  * @param boolean $recursive
  * @return void
  * @throws \InvalidArgumentException if the given node path is invalid.
  */
 public function setPath($path, $recursive = true)
 {
     if (!is_string($path) || preg_match(NodeInterface::MATCH_PATTERN_PATH, $path) !== 1) {
         throw new \InvalidArgumentException('Invalid path "' . $path . '" (a path must be a valid string, be absolute (starting with a slash) and contain only the allowed characters).', 1284369857);
     }
     if ($path === $this->path) {
         return;
     }
     if ($recursive === true) {
         /** @var $childNodeData NodeData */
         foreach ($this->getChildNodeData() as $childNodeData) {
             $childNodeData->setPath(NodePaths::addNodePathSegment($path, $childNodeData->getName()));
         }
     }
     $pathBeforeChange = $this->path;
     $this->path = $path;
     $this->calculatePathHash();
     $this->parentPath = NodePaths::getParentPath($path);
     $this->calculateParentPathHash();
     $this->depth = NodePaths::getPathDepth($path);
     if ($pathBeforeChange !== null) {
         // this method is called both for changing the path AND in the constructor of Node; so we only want to do
         // these things below if called OUTSIDE a constructor.
         $this->emitNodePathChanged($this);
         $this->addOrUpdate();
     }
 }
All Usage Examples Of Neos\ContentRepository\Domain\Utility\NodePaths::getParentPath