public function createRelation($contentId, $versionNumber, Request $request)
    {
        $destinationContentId = $this->inputDispatcher->parse(
            new Message(
                array('Content-Type' => $request->headers->get('Content-Type')),
                $request->getContent()
            )
        );

        $contentInfo = $this->repository->getContentService()->loadContentInfo($contentId);
        $versionInfo = $this->repository->getContentService()->loadVersionInfo($contentInfo, $versionNumber);
        if (!$versionInfo->isDraft()) {
            throw new ForbiddenException('Relation of type COMMON can only be added to drafts');
        }

        try {
            $destinationContentInfo = $this->repository->getContentService()->loadContentInfo($destinationContentId);
        } catch (NotFoundException $e) {
            throw new ForbiddenException($e->getMessage());
        }

        $existingRelations = $this->repository->getContentService()->loadRelations($versionInfo);
        foreach ($existingRelations as $existingRelation) {
            if ($existingRelation->getDestinationContentInfo()->id == $destinationContentId) {
                throw new ForbiddenException('Relation of type COMMON to selected destination content ID already exists');
            }
        }

        $relation = $this->repository->getContentService()->addRelation($versionInfo, $destinationContentInfo);

        return new Values\CreatedRelation(
            array(
                'relation' => new Values\RestRelation($relation, $contentId, $versionNumber),
            )
        );
    }
public function createRelation($contentId, $versionNumber, Request $request)
    {
        $destinationContentId = $this->inputDispatcher->parse(
            new Message(
                array('Content-Type' => $request->headers->get('Content-Type')),
                $request->getContent()
            )
        );

        $contentInfo = $this->repository->getContentService()->loadContentInfo($contentId);
        $versionInfo = $this->repository->getContentService()->loadVersionInfo($contentInfo, $versionNumber);
        if (!$versionInfo->isDraft()) {
            throw new ForbiddenException('Relation of type COMMON can only be added to drafts');
        }

        try {
            $destinationContentInfo = $this->repository->getContentService()->loadContentInfo($destinationContentId);
        } catch (NotFoundException $e) {
            throw new ForbiddenException($e->getMessage());
        }

        $existingRelations = $this->repository->getContentService()->loadRelations($versionInfo);
        foreach ($existingRelations as $existingRelation) {
            if ($existingRelation->getDestinationContentInfo()->id == $destinationContentId) {
                throw new ForbiddenException('Relation of type COMMON to selected destination content ID already exists');
            }
        }

        $relation = $this->repository->getContentService()->addRelation($versionInfo, $destinationContentInfo);

        return new Values\CreatedRelation(
            array(
                'relation' => new Values\RestRelation($relation, $contentId, $versionNumber),
            )
        );
    }
public function createRelation ( $ contentId , $ versionNumber , Request $ request ) { $ destinationContentId = $ this -> inputDispatcher -> parse ( new Message ( array ( 'Content-Type' => $ request -> headers -> get ( 'Content-Type' ) ) , $ request -> getContent ( ) ) ) ; $ contentInfo = $ this -> repository -> getContentService ( ) -> loadContentInfo ( $ contentId ) ; $ versionInfo = $ this -> repository -> getContentService ( ) -> loadVersionInfo ( $ contentInfo , $ versionNumber ) ; if ( ! $ versionInfo -> isDraft ( ) ) { throw new ForbiddenException ( 'Relation of type COMMON can only be added to drafts' ) ; } try { $ destinationContentInfo = $ this -> repository -> getContentService ( ) -> loadContentInfo ( $ destinationContentId ) ; } catch ( NotFoundException $ e ) { throw new ForbiddenException ( $ e -> getMessage ( ) ) ; } $ existingRelations = $ this -> repository -> getContentService ( ) -> loadRelations ( $ versionInfo ) ; foreach ( $ existingRelations as $ existingRelation ) { if ( $ existingRelation -> getDestinationContentInfo ( ) -> id == $ destinationContentId ) { throw new ForbiddenException ( 'Relation of type COMMON to selected destination content ID already exists' ) ; } } $ relation = $ this -> repository -> getContentService ( ) -> addRelation ( $ versionInfo , $ destinationContentInfo ) ; return new Values \ CreatedRelation ( array ( 'relation' => new Values \ RestRelation ( $ relation , $ contentId , $ versionNumber ) , ) ) ; }
Creates a new relation of type COMMON for the given draft.

@param mixed $contentId
@param int $versionNumber

@throws ForbiddenException if version $versionNumber isn't a draft
@throws ForbiddenException if a relation to the same content already exists

@return \eZ\Publish\Core\REST\Server\Values\CreatedRelation
Creates a new relation of type COMMON for the given draft .