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;
}