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

setKey() public method

public setKey ( string $key )
$key string
    public function setKey($key)
    {
        $this->key = $key;
        return $this;
    }

Usage Example

 public function createFieldCollection($name, $jsonPath = null)
 {
     try {
         $fieldCollection = Object\Fieldcollection\Definition::getByKey($name);
     } catch (\Exception $e) {
         if ($jsonPath == null) {
             $jsonPath = PIMCORE_PLUGINS_PATH . "/CoreShop/install/fieldcollection-{$name}.json";
         }
         $fieldCollection = new Object\Fieldcollection\Definition();
         $fieldCollection->setKey($name);
         $json = file_get_contents($jsonPath);
         $result = Plugin::getEventManager()->trigger('install.fieldcollection.preCreate', $this, array("fieldcollectionName" => $name, "json" => $json), function ($v) {
             return !preg_match('/[^,:{}\\[\\]0-9.\\-+Eaeflnr-u \\n\\r\\t]/', preg_replace('/"(\\.|[^"\\\\])*"/', '', $v));
         });
         if ($result->stopped()) {
             $resultJson = $result->last();
             if ($resultJson) {
                 $json = $resultJson;
             }
         }
         Object\ClassDefinition\Service::importFieldCollectionFromJson($fieldCollection, $json, true);
     }
     return $fieldCollection;
 }
All Usage Examples Of Pimcore\Model\Object\Fieldcollection\Definition::setKey