Pimcore\Model\Object\Fieldcollection\Definition::getByKey PHP Method

getByKey() public static method

public static getByKey ( $key )
$key
    public static function getByKey($key)
    {
        $fc = null;
        $cacheKey = "fieldcollection_" . $key;
        try {
            $fc = \Zend_Registry::get($cacheKey);
            if (!$fc) {
                throw new \Exception("FieldCollection in registry is not valid");
            }
        } catch (\Exception $e) {
            $fieldCollectionFolder = PIMCORE_CLASS_DIRECTORY . "/fieldcollections";
            $fieldFile = $fieldCollectionFolder . "/" . $key . ".php";
            if (is_file($fieldFile)) {
                $fc = (include $fieldFile);
                \Zend_Registry::set($cacheKey, $fc);
            }
        }
        if ($fc) {
            return $fc;
        }
        throw new \Exception("Field-Collection with key: " . $key . " does not exist.");
    }

Usage Example

 /**
  * Try to load definition by name
  *
  * @param $name
  * @return AbstractModel|null
  */
 protected function loadDefinition($name)
 {
     try {
         return Definition::getByKey($name);
     } catch (\Exception $e) {
         // noop
     }
 }
All Usage Examples Of Pimcore\Model\Object\Fieldcollection\Definition::getByKey