eZ\Publish\Core\REST\Server\Controller\ContentType::createContentType PHP Method

createContentType() public method

Creates a new content type draft in the given content type group.
public createContentType ( $contentTypeGroupId, Request $request ) : CreatedContentType
$contentTypeGroupId
$request Symfony\Component\HttpFoundation\Request
return eZ\Publish\Core\REST\Server\Values\CreatedContentType
    public function createContentType($contentTypeGroupId, Request $request)
    {
        $contentTypeGroup = $this->contentTypeService->loadContentTypeGroup($contentTypeGroupId);
        $publish = $request->query->has('publish') && $request->query->get('publish') === 'true';
        try {
            $contentTypeDraft = $this->contentTypeService->createContentType($this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type'), '__publish' => $publish), $request->getContent())), array($contentTypeGroup));
        } catch (InvalidArgumentException $e) {
            throw new ForbiddenException($e->getMessage());
        } catch (ContentTypeValidationException $e) {
            throw new BadRequestException($e->getMessage());
        } catch (ContentTypeFieldDefinitionValidationException $e) {
            throw new BadRequestException($e->getMessage());
        } catch (Exceptions\Parser $e) {
            throw new BadRequestException($e->getMessage());
        }
        if ($publish) {
            $this->contentTypeService->publishContentTypeDraft($contentTypeDraft);
            $contentType = $this->contentTypeService->loadContentType($contentTypeDraft->id);
            return new Values\CreatedContentType(array('contentType' => new Values\RestContentType($contentType, $contentType->getFieldDefinitions())));
        }
        return new Values\CreatedContentType(array('contentType' => new Values\RestContentType($contentTypeDraft, $contentTypeDraft->getFieldDefinitions())));
    }