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

getElementByPath() public static method

public static getElementByPath ( string $type, string $path ) : Pimcore\Model\Element\ElementInterface
$type string
$path string
return Pimcore\Model\Element\ElementInterface
    public static function getElementByPath($type, $path)
    {
        if ($type == "asset") {
            $element = Asset::getByPath($path);
        } elseif ($type == "object") {
            $element = Object::getByPath($path);
        } elseif ($type == "document") {
            $element = Document::getByPath($path);
        }
        return $element;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Takes data from editmode and convert it to internal objects
  *
  * @param mixed $data
  * @return void
  */
 public function setDataFromEditmode($data)
 {
     // IMPORTANT: if you use this method be sure that the type of the property is already set
     if (in_array($this->getType(), array("document", "asset", "object"))) {
         $el = Element\Service::getElementByPath($this->getType(), $data);
         $this->data = null;
         if ($el) {
             $this->data = $el->getId();
         }
     } else {
         if ($this->type == "date") {
             $this->data = new \Zend_Date($data);
         } else {
             if ($this->type == "bool") {
                 $this->data = false;
                 if (!empty($data)) {
                     $this->data = true;
                 }
             } else {
                 // plain text
                 $this->data = $data;
             }
         }
     }
     return $this;
 }
All Usage Examples Of Pimcore\Model\Element\Service::getElementByPath