Pimcore\Model\Object\ClassDefinition\Service::generateObjectBrickJson PHP Метод

generateObjectBrickJson() публичный статический Метод

public static generateObjectBrickJson ( $objectBrick ) : string
$objectBrick
Результат string
    public static function generateObjectBrickJson($objectBrick)
    {
        unset($objectBrick->key);
        unset($objectBrick->fieldDefinitions);
        // set classname attribute to the real class name not to the class ID
        // this will allow to import the brick on a different instance with identical class names but different class IDs
        if (is_array($objectBrick->classDefinitions)) {
            foreach ($objectBrick->classDefinitions as &$cd) {
                $class = Object\ClassDefinition::getById($cd["classname"]);
                if ($class) {
                    $cd["classname"] = $class->getName();
                }
            }
        }
        $json = \Zend_Json::encode($objectBrick);
        $json = \Zend_Json::prettyPrint($json);
        return $json;
    }

Usage Example

Пример #1
0
 /**
  * See http://www.pimcore.org/issues/browse/PIMCORE-2358
  * Add option to export/import all class definitions/brick definitions etc. at once
  */
 public function bulkExportAction()
 {
     $result = [];
     $this->removeViewRenderer();
     $fieldCollections = new Object\Fieldcollection\Definition\Listing();
     $fieldCollections = $fieldCollections->load();
     foreach ($fieldCollections as $fieldCollection) {
         $key = $fieldCollection->key;
         $fieldCollectionJson = json_decode(Object\ClassDefinition\Service::generateFieldCollectionJson($fieldCollection));
         $fieldCollectionJson->key = $key;
         $result["fieldcollection"][] = $fieldCollectionJson;
     }
     $classes = new Object\ClassDefinition\Listing();
     $classes->setOrder("ASC");
     $classes->setOrderKey("id");
     $classes = $classes->load();
     foreach ($classes as $class) {
         $data = Model\Webservice\Data\Mapper::map($class, "\\Pimcore\\Model\\Webservice\\Data\\ClassDefinition\\Out", "out");
         unset($data->fieldDefinitions);
         $result["class"][] = $data;
     }
     $objectBricks = new Object\Objectbrick\Definition\Listing();
     $objectBricks = $objectBricks->load();
     foreach ($objectBricks as $objectBrick) {
         $key = $objectBrick->key;
         $objectBrickJson = json_decode(Object\ClassDefinition\Service::generateObjectBrickJson($objectBrick));
         $objectBrickJson->key = $key;
         $result["objectbrick"][] = $objectBrickJson;
     }
     $customLayouts = new Object\ClassDefinition\CustomLayout\Listing();
     $customLayouts = $customLayouts->load();
     foreach ($customLayouts as $customLayout) {
         /** @var  $customLayout Object\ClassDefinition\CustomLayout */
         $classId = $customLayout->getClassId();
         $class = Object\ClassDefinition::getById($classId);
         $customLayout->className = $class->getName();
         $result["customlayout"][] = $customLayout;
     }
     header("Content-type: application/json");
     header("Content-Disposition: attachment; filename=\"bulk_export.json\"");
     $result = json_encode($result);
     echo $result;
 }