/** * Assigns a content type to a content type group. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to unlink a content type * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the content type is already assigned the given group * * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup $contentTypeGroup */ public function assignContentTypeGroup( APIContentType $contentType, APIContentTypeGroup $contentTypeGroup ) { if ( $this->repository->hasAccess( 'class', 'update' ) !== true ) throw new UnauthorizedException( 'ContentType', 'update' ); $spiContentType = $this->contentTypeHandler->load( $contentType->id, $contentType->status ); if ( in_array( $contentTypeGroup->id, $spiContentType->groupIds ) ) { throw new InvalidArgumentException( "\$contentTypeGroup", "The given ContentType is already assigned to the ContentTypeGroup" ); } $this->repository->beginTransaction(); try { $this->contentTypeHandler->link( $contentTypeGroup->id, $contentType->id, $contentType->status ); $this->repository->commit(); } catch ( Exception $e ) { $this->repository->rollback(); throw $e; } }
/** * Link a content type group with a content type * * @param mixed $groupId * @param mixed $contentTypeId * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If group or type with provided status is not found * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If type is already part of group * @todo Above throws are not implemented */ public function link($groupId, $contentTypeId, $status) { $this->clearCache(); return $this->innerHandler->link($groupId, $contentTypeId, $status); }