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

removeRelation() public method

Deletes a relation of the given draft.
public removeRelation ( mixed $contentId, integer $versionNumber, mixed $relationId, Request $request ) : eZ\Publish\Core\REST\Server\Values\NoContent
$contentId mixed
$versionNumber integer
$relationId mixed
$request Symfony\Component\HttpFoundation\Request
return eZ\Publish\Core\REST\Server\Values\NoContent
    public function removeRelation($contentId, $versionNumber, $relationId, Request $request)
    {
        $versionInfo = $this->repository->getContentService()->loadVersionInfo($this->repository->getContentService()->loadContentInfo($contentId), $versionNumber);
        $versionRelations = $this->repository->getContentService()->loadRelations($versionInfo);
        foreach ($versionRelations as $relation) {
            if ($relation->id == $relationId) {
                if ($relation->type !== Relation::COMMON) {
                    throw new ForbiddenException('Relation is not of type COMMON');
                }
                if ($versionInfo->status !== VersionInfo::STATUS_DRAFT) {
                    throw new ForbiddenException('Relation of type COMMON can only be removed from drafts');
                }
                $this->repository->getContentService()->deleteRelation($versionInfo, $relation->getDestinationContentInfo());
                return new Values\NoContent();
            }
        }
        throw new Exceptions\NotFoundException("Relation not found: '{$request->getPathInfo()}'.");
    }