Pimcore\Model\Element\Service::getTypePath PHP Method

getTypePath() public static method

public static getTypePath ( $element ) : string
$element
return string
    public static function getTypePath($element)
    {
        $path = "";
        if ($element instanceof ElementInterface) {
            $elementType = self::getElementType($element);
            $nid = $element->getParentId();
            $ne = self::getElementById($elementType, $nid);
        }
        if ($ne) {
            $path = self::getTypePath($ne, $path);
        }
        if ($element) {
            $type = $element->getType();
            if ($type != "folder") {
                if ($element instanceof Document) {
                    $type = "document";
                } elseif ($element instanceof Object\AbstractObject) {
                    $type = "object";
                } elseif ($element instanceof Asset) {
                    $type = "asset";
                } else {
                    throw new \Exception("unknown type");
                }
            }
            $path = $path . "/" . $type;
        }
        return $path;
    }

Usage Example

Example #1
0
 public function typePathAction()
 {
     $id = $this->getParam("id");
     $type = $this->getParam("type");
     $data = [];
     if ($type == "asset") {
         $element = Asset::getById($id);
     } elseif ($type == "document") {
         $element = Document::getById($id);
         $data["index"] = $element->getIndex();
     } else {
         $element = Object::getById($id);
     }
     $typePath = Element\Service::getTypePath($element);
     $data["success"] = true;
     $data["idPath"] = Element\Service::getIdPath($element);
     $data["typePath"] = $typePath;
     $data["fullpath"] = $element->getRealFullPath();
     $this->_helper->json($data);
 }