Pimcore\Model\Metadata\Predefined::getByName PHP Method

getByName() public static method

public static getByName ( $name, $language = "" ) : self
return self
    public static function getByName($name, $language = "")
    {
        try {
            $metadata = new self();
            $metadata->setName($name);
            $metadata->getDao()->getByNameAndLanguage($name, $language);
            return $metadata;
        } catch (\Exception $e) {
            return null;
        }
    }

Usage Example

Beispiel #1
0
 /**
  * @param $metadata
  * @return array
  */
 public static function expandMetadataForEditmode($metadata)
 {
     if (!is_array($metadata)) {
         return $metadata;
     }
     $result = [];
     foreach ($metadata as $item) {
         $type = $item["type"];
         switch ($type) {
             case "document":
             case "asset":
             case "object":
                 $element = $item["data"];
                 if (is_numeric($item["data"])) {
                     $element = Element\Service::getElementById($type, $item["data"]);
                 }
                 if ($element instanceof Element\ElementInterface) {
                     $item["data"] = $element->getRealFullPath();
                 } else {
                     $item["data"] = "";
                 }
                 break;
             default:
                 //nothing to do
         }
         //get the config from an predefined property-set (eg. select)
         $predefined = Model\Metadata\Predefined::getByName($item['name']);
         if ($predefined && $predefined->getType() == $item['type'] && $predefined->getConfig()) {
             $item['config'] = $predefined->getConfig();
         }
         $result[] = $item;
     }
     return $result;
 }