Jackalope\Item::setPath PHP Method

setPath() public method

Set or update the path, depth, name and parent reference
public setPath ( string $path, boolean $move = false )
$path string the new path this item lives at
$move boolean whether this item is being moved in session context and should store the current path until the next save operation.
    public function setPath($path, $move = false)
    {
        if ($move && null === $this->oldPath) {
            try {
                $this->checkState();
            } catch (InvalidItemStateException $e) {
                // do not break if object manager tells the move to a child that was removed in backend
                return;
            }
            $this->oldPath = $this->path;
        }
        $this->path = $path;
        $this->depth = '/' === $path ? 0 : substr_count($path, '/');
        $this->name = PathHelper::getNodeName($path);
        $this->parentPath = 0 === $this->depth ? null : PathHelper::getParentPath($path);
    }

Usage Example

Example #1
0
 /**
  * In addition to calling parent method, tell all properties
  */
 public function setPath($path, $move = false)
 {
     parent::setPath($path, $move);
     foreach ($this->properties as $property) {
         $property->setPath($path . '/' . $property->getName(), $move);
     }
 }