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

addContentTypeDraftFieldDefinition() public method

Creates a new field definition for the given content type draft.
public addContentTypeDraftFieldDefinition ( $contentTypeId, Request $request ) : CreatedFieldDefinition
$contentTypeId
$request Symfony\Component\HttpFoundation\Request
return eZ\Publish\Core\REST\Server\Values\CreatedFieldDefinition
    public function addContentTypeDraftFieldDefinition($contentTypeId, Request $request)
    {
        $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($contentTypeId);
        $fieldDefinitionCreate = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type')), $request->getContent()));
        try {
            $this->contentTypeService->addFieldDefinition($contentTypeDraft, $fieldDefinitionCreate);
        } catch (InvalidArgumentException $e) {
            throw new ForbiddenException($e->getMessage());
        } catch (ContentTypeFieldDefinitionValidationException $e) {
            throw new BadRequestException($e->getMessage());
        } catch (BadStateException $e) {
            throw new ForbiddenException($e->getMessage());
        }
        $updatedDraft = $this->contentTypeService->loadContentTypeDraft($contentTypeId);
        foreach ($updatedDraft->getFieldDefinitions() as $fieldDefinition) {
            if ($fieldDefinition->identifier == $fieldDefinitionCreate->identifier) {
                return new Values\CreatedFieldDefinition(array('fieldDefinition' => new Values\RestFieldDefinition($updatedDraft, $fieldDefinition)));
            }
        }
        throw new Exceptions\NotFoundException("Field definition not found: '{$request->getPathInfo()}'.");
    }