/** * Export a content type in Json format * * @param integer $id * @param Request $request * @Route("/content-type/export/{contentType}.{_format}", defaults={"_format" = "json"}, name="contenttype.export")) */ public function exportAction(ContentType $contentType, Request $request) { //Sanitize the CT $contentType->setCreated(NULL); $contentType->setModified(NULL); $contentType->getFieldType()->removeCircularReference(); $contentType->setEnvironment(NULL); //$contentType->getTemplates()->clear(); //$contentType->getViews()->clear(); //Serialize the CT $encoders = array(new JsonEncoder()); $normalizers = array(new JsonNormalizer()); $serializer = new Serializer($normalizers, $encoders); $jsonContent = $serializer->serialize($contentType, 'json'); $response = new Response($jsonContent); $diposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $contentType->getName() . '.json'); $response->headers->set('Content-Disposition', $diposition); return $response; }
private function createContentType($name, $pluralName, $icon, $description, $indexTwig, $extra, $color, $orderKey, $rootContentType, $active, $environment, $labelField, $locationField) { $contentType = new ContentType(); $contentType->setName($name); $contentType->setPluralName($pluralName); $contentType->setIcon($icon); $contentType->setDescription($description); $contentType->setIndexTwig($indexTwig); $contentType->setExtra($extra); $contentType->setColor($color); $contentType->setOrderKey($orderKey); $contentType->setRootContentType($rootContentType); $contentType->setActive($active); $contentType->setEnvironment($this->getReference($environment)); $contentType->setLabelField($labelField); $contentType->setLocationField($locationField); return $contentType; }