eZ\Publish\Core\REST\Server\Controller\Content::createContent PHP Method

createContent() public method

If a different userId is given in the input it is assigned to the given user but this required special rights for the authenticated user (this is useful for content staging where the transfer process does not have to authenticate with the user which created the content object in the source server). The user has to publish the content if it should be visible.
public createContent ( Request $request ) : CreatedContent
$request Symfony\Component\HttpFoundation\Request
return eZ\Publish\Core\REST\Server\Values\CreatedContent
    public function createContent(Request $request)
    {
        $contentCreate = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type')), $request->getContent()));
        try {
            $content = $this->repository->getContentService()->createContent($contentCreate->contentCreateStruct, array($contentCreate->locationCreateStruct));
        } catch (ContentValidationException $e) {
            throw new BadRequestException($e->getMessage());
        } catch (ContentFieldValidationException $e) {
            throw new RESTContentFieldValidationException($e);
        }
        $contentValue = null;
        $contentType = null;
        $relations = null;
        if ($this->getMediaType($request) === 'application/vnd.ez.api.content') {
            $contentValue = $content;
            $contentType = $this->repository->getContentTypeService()->loadContentType($content->getVersionInfo()->getContentInfo()->contentTypeId);
            $relations = $this->repository->getContentService()->loadRelations($contentValue->getVersionInfo());
        }
        return new Values\CreatedContent(array('content' => new Values\RestContent($content->contentInfo, null, $contentValue, $contentType, $relations)));
    }

Usage Example

Exemplo n.º 1
0
 public function createContent(Request $request)
 {
     if (!$this->isUserCreateRequest($request)) {
         return parent::createContent($request);
     }
     $createdUser = $this->repository->getUserService()->createUser($this->mapRequestToUserCreateStruct($request), $this->mapRequestToParentGroups($request));
     return $this->mapUserToCreatedContent($createdUser);
 }