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

getDependedElement() public static method

public static getDependedElement ( array $config ) : AbstractObject | Document | Asset
$config array
return Pimcore\Model\Object\AbstractObject | Pimcore\Model\Document | Pimcore\Model\Asset
    public static function getDependedElement($config)
    {
        if ($config["type"] == "object") {
            return Object::getById($config["id"]);
        } elseif ($config["type"] == "asset") {
            return Asset::getById($config["id"]);
        } elseif ($config["type"] == "document") {
            return Document::getById($config["id"]);
        }
        return false;
    }

Usage Example

コード例 #1
0
ファイル: Service.php プロジェクト: ChristophWurst/pimcore
 public function extractRelations($element, $apiElementKeys, $recursive, $includeRelations)
 {
     $foundRelations = array();
     if ($includeRelations) {
         $dependency = $element->getDependencies();
         if ($dependency) {
             foreach ($dependency->getRequires() as $r) {
                 if ($e = Element\Service::getDependedElement($r)) {
                     if ($element->getId() != $e->getId() and !in_array(Element\Service::getElementType($e) . "_" . $e->getId(), $apiElementKeys)) {
                         $foundRelations[Element\Service::getElementType($e) . "_" . $e->getId()] = array("elementType" => Element\Service::getType($e), "element" => $e->getId(), "recursive" => false);
                     }
                 }
             }
         }
     }
     $childs = $element->getChilds();
     if ($recursive and $childs) {
         foreach ($childs as $child) {
             if (!in_array(Element\Service::getType($child) . "_" . $child->getId(), $apiElementKeys)) {
                 $foundRelations[Element\Service::getType($child) . "_" . $child->getId()] = array("elementType" => Element\Service::getType($child), "element" => $child->getId(), "recursive" => $recursive);
             }
         }
     }
     return $foundRelations;
 }