Pimcore\Model\Metadata\Predefined\Listing::getByTargetType PHP Method

getByTargetType() public static method

public static getByTargetType ( $type, $subTypes ) : Listing
$type
$subTypes
return Listing
    public static function getByTargetType($type, $subTypes)
    {
        if ($type != "asset") {
            throw new \Exception("other types than assets are currently not supported");
        }
        $list = new self();
        if ($subTypes && !is_array($subTypes)) {
            $subTypes = [$subTypes];
        }
        if (is_array($subTypes)) {
            $list->setFilter(function ($row) use($subTypes) {
                if (empty($row["targetSubtype"])) {
                    return true;
                }
                if (in_array($row["targetSubtype"], $subTypes)) {
                    return true;
                }
                return false;
            });
        }
        $list = $list->load();
        return $list;
    }

Usage Example

 public function getPredefinedMetadataAction()
 {
     $type = $this->getParam("type");
     $subType = $this->getParam("subType");
     $list = Metadata\Predefined\Listing::getByTargetType($type, array($subType));
     $result = array();
     foreach ($list as $item) {
         /** @var $item Metadata\Predefined */
         $item->expand();
         $result[] = $item;
     }
     $this->_helper->json(array("data" => $result, "success" => true));
 }