Pimcore\Model\Object\ClassDefinition\Service::importFieldCollectionFromJson PHP Method

importFieldCollectionFromJson() public static method

public static importFieldCollectionFromJson ( $fieldCollection, $json, $throwException = false ) : boolean
$fieldCollection
$json
return boolean
    public static function importFieldCollectionFromJson($fieldCollection, $json, $throwException = false)
    {
        $importData = \Zend_Json::decode($json);
        if (!is_null($importData["layoutDefinitions"])) {
            $layout = self::generateLayoutTreeFromArray($importData["layoutDefinitions"], $throwException);
            $fieldCollection->setLayoutDefinitions($layout);
        }
        $fieldCollection->setParentClass($importData["parentClass"]);
        $fieldCollection->save();
        return true;
    }

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\ClassDefinition\Service::importFieldCollectionFromJson