Interface

eZ\Publish\API\Repository\ContentService

interface ContentService

This class provides service methods for managing content.

Methods

ContentInfo loadContentInfo(int $contentId)

Loads a content info object.

ContentInfo loadContentInfoByRemoteId(string $remoteId)

Loads a content info object for the given remoteId.

VersionInfo loadVersionInfo(ContentInfo $contentInfo, int $versionNo = null)

Loads a version info of the given content object.

VersionInfo loadVersionInfoById(mixed $contentId, int $versionNo = null)

Loads a version info of the given content object id.

Content loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, int $versionNo = null, bool $useAlwaysAvailable = true)

Loads content in a version for the given content info object.

Content loadContentByVersionInfo(VersionInfo $versionInfo, array $languages = null, bool $useAlwaysAvailable = true)

Loads content in the version given by version info.

Content loadContent(mixed $contentId, array $languages = null, int $versionNo = null, bool $useAlwaysAvailable = true)

Loads content in a version of the given content object.

Content loadContentByRemoteId(string $remoteId, array $languages = null, int $versionNo = null, bool $useAlwaysAvailable = true)

Loads content in a version for the content object reference by the given remote id.

Content createContent(ContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array())

Creates a new content draft assigned to the authenticated user.

Content updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct)

Updates the metadata.

mixed[] deleteContent(ContentInfo $contentInfo)

Deletes a content object including all its versions and locations including their subtrees.

Content createContentDraft(ContentInfo $contentInfo, VersionInfo $versionInfo = null, User $creator = null)

Creates a draft from a published or archived version.

VersionInfo[] loadContentDrafts(User $user = null)

Loads drafts for a user.

Content updateContent(VersionInfo $versionInfo, ContentUpdateStruct $contentUpdateStruct)

Updates the fields of a draft.

Content publishVersion(VersionInfo $versionInfo)

Publishes a content version.

deleteVersion(VersionInfo $versionInfo)

Removes the given version.

VersionInfo[] loadVersions(ContentInfo $contentInfo)

Loads all versions for the given content.

Content copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, VersionInfo $versionInfo = null)

Copies the content to a new location.

Relation[] loadRelations(VersionInfo $versionInfo)

Loads all outgoing relations for the given version.

Relation[] loadReverseRelations(ContentInfo $contentInfo)

Loads all incoming relations for a content object.

Relation addRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent)

Adds a relation of type common.

deleteRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent)

Removes a relation of type COMMON from a draft.

removeTranslation(ContentInfo $contentInfo, string $languageCode)

Remove Content Object translation from all Versions (including archived ones) of a Content Object.

deleteTranslation(ContentInfo $contentInfo, string $languageCode)

Delete Content item Translation from all Versions (including archived ones) of a Content Object.

Content deleteTranslationFromDraft(VersionInfo $versionInfo, string $languageCode)

Delete specified Translation from a Content Draft.

ContentCreateStruct newContentCreateStruct(ContentType $contentType, string $mainLanguageCode)

Instantiates a new content create struct object.

ContentMetadataUpdateStruct newContentMetadataUpdateStruct()

Instantiates a new content meta data update struct.

ContentUpdateStruct newContentUpdateStruct()

Instantiates a new content update struct.

Details

at line 39
public ContentInfo loadContentInfo(int $contentId)

Loads a content info object.

To load fields use loadContent

Parameters

int $contentId

Return Value

ContentInfo

Exceptions

UnauthorizedException if the user is not allowed to read the content
NotFoundException
  • if the content with the given id does not exist

at line 53
public ContentInfo loadContentInfoByRemoteId(string $remoteId)

Loads a content info object for the given remoteId.

To load fields use loadContent

Parameters

string $remoteId

Return Value

ContentInfo

Exceptions

UnauthorizedException if the user is not allowed to read the content
NotFoundException
  • if the content with the given remote id does not exist

at line 68
public VersionInfo loadVersionInfo(ContentInfo $contentInfo, int $versionNo = null)

Loads a version info of the given content object.

If no version number is given, the method returns the current version

Parameters

ContentInfo $contentInfo
int $versionNo the version number. If not given the current version is returned.

Return Value

VersionInfo

Exceptions

NotFoundException
  • if the version with the given number does not exist
UnauthorizedException if the user is not allowed to load this version

at line 83
public VersionInfo loadVersionInfoById(mixed $contentId, int $versionNo = null)

Loads a version info of the given content object id.

If no version number is given, the method returns the current version

Parameters

mixed $contentId
int $versionNo the version number. If not given the current version is returned.

Return Value

VersionInfo

Exceptions

NotFoundException
  • if the version with the given number does not exist
UnauthorizedException if the user is not allowed to load this version

at line 101
public Content loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, int $versionNo = null, bool $useAlwaysAvailable = true)

Loads content in a version for the given content info object.

If no version number is given, the method returns the current version

Parameters

ContentInfo $contentInfo
array $languages A language priority, filters returned fields and is used as prioritized language code on returned value object. If not given all languages are returned.
int $versionNo the version number. If not given the current version is returned from $contentInfo
bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true

Return Value

Content

Exceptions

NotFoundException
  • if version with the given number does not exist
UnauthorizedException if the user is not allowed to load this version

at line 115
public Content loadContentByVersionInfo(VersionInfo $versionInfo, array $languages = null, bool $useAlwaysAvailable = true)

Loads content in the version given by version info.

Parameters

VersionInfo $versionInfo
array $languages A language priority, filters returned fields and is used as prioritized language code on returned value object. If not given all languages are returned.
bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true

Return Value

Content

Exceptions

UnauthorizedException if the user is not allowed to load this version

at line 133
public Content loadContent(mixed $contentId, array $languages = null, int $versionNo = null, bool $useAlwaysAvailable = true)

Loads content in a version of the given content object.

If no version number is given, the method returns the current version

Parameters

mixed $contentId
array $languages A language priority, filters returned fields and is used as prioritized language code on returned value object. If not given all languages are returned.
int $versionNo the version number. If not given the current version is returned
bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true

Return Value

Content

Exceptions

NotFoundException if the content or version with the given id and languages does not exist
UnauthorizedException If the user has no access to read content and in case of un-published content: read versions

at line 151
public Content loadContentByRemoteId(string $remoteId, array $languages = null, int $versionNo = null, bool $useAlwaysAvailable = true)

Loads content in a version for the content object reference by the given remote id.

If no version is given, the method returns the current version

Parameters

string $remoteId
array $languages A language priority, filters returned fields and is used as prioritized language code on returned value object. If not given all languages are returned.
int $versionNo the version number. If not given the current version is returned
bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true

Return Value

Content

Exceptions

NotFoundException
  • if the content or version with the given remote id does not exist
UnauthorizedException If the user has no access to read content and in case of un-published content: read versions

at line 175
public Content createContent(ContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array())

Creates a new content draft assigned to the authenticated user.

If a different userId is given in $contentCreateStruct 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 draft if it should be visible. In 4.x at least one location has to be provided in the location creation array.

Parameters

ContentCreateStruct $contentCreateStruct
array $locationCreateStructs an array of {@link \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct} for each location parent under which a location should be created for the content

Return Value

Content
  • the newly created content draft

Exceptions

UnauthorizedException if the user is not allowed to create the content in the given location
InvalidArgumentException if there is a provided remoteId which exists in the system or there is no location provided (4.x) or multiple locations are under the same parent or if the a field value is not accepted by the field type
ContentFieldValidationException if a field in the $contentCreateStruct is not valid
ContentValidationException if a required field is missing or is set to an empty value

at line 190
public Content updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct)

Updates the metadata.

(see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent

Parameters

ContentInfo $contentInfo
ContentMetadataUpdateStruct $contentMetadataUpdateStruct

Return Value

Content the content with the updated attributes

Exceptions

UnauthorizedException if the user is not allowed to update the content meta data
InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists

at line 201
public mixed[] deleteContent(ContentInfo $contentInfo)

Deletes a content object including all its versions and locations including their subtrees.

Parameters

ContentInfo $contentInfo

Return Value

mixed[] Affected Location Id's (List of Locations of the Content that was deleted)

Exceptions

UnauthorizedException if the user is not allowed to delete the content (in one of the locations of the given content object)

at line 218
public Content createContentDraft(ContentInfo $contentInfo, VersionInfo $versionInfo = null, User $creator = null)

Creates a draft from a published or archived version.

If no version is given, the current published version is used. 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language. It can be changed on updating the version.

Parameters

ContentInfo $contentInfo
VersionInfo $versionInfo
User $creator Used as creator of the draft if given - otherwise uses current-user

Return Value

Content
  • the newly created content draft

Exceptions

UnauthorizedException if the current-user is not allowed to create the draft

at line 231
public VersionInfo[] loadContentDrafts(User $user = null)

Loads drafts for a user.

If no user is given the drafts for the authenticated user a returned

Parameters

User $user The user to load drafts from if defined, otherwise drafts for current-user

Return Value

VersionInfo[] the drafts ({@link VersionInfo}) owned by the given user

Exceptions

UnauthorizedException if the current-user is not allowed to load the draft list

at line 247
public Content updateContent(VersionInfo $versionInfo, ContentUpdateStruct $contentUpdateStruct)

Updates the fields of a draft.

Parameters

VersionInfo $versionInfo
ContentUpdateStruct $contentUpdateStruct

Return Value

Content the content draft with the updated fields

Exceptions

UnauthorizedException if the user is not allowed to update this version
BadStateException if the version is not a draft
ContentFieldValidationException if a field in the $contentUpdateStruct is not valid
ContentValidationException if a required field is set to an empty value
InvalidArgumentException if a field value is not accepted by the field type

at line 263
public Content publishVersion(VersionInfo $versionInfo)

Publishes a content version.

Publishes a content version and deletes archive versions if they overflow max archive versions. Max archive versions are currently a configuration for default max limit, by default set to 5.

Parameters

VersionInfo $versionInfo

Return Value

Content

Exceptions

UnauthorizedException if the user is not allowed to publish this version
BadStateException if the version is not a draft

at line 274
public deleteVersion(VersionInfo $versionInfo)

Removes the given version.

Parameters

VersionInfo $versionInfo

Exceptions

BadStateException if the version is in published state or is a last version of the Content
UnauthorizedException if the user is not allowed to remove this version

at line 285
public VersionInfo[] loadVersions(ContentInfo $contentInfo)

Loads all versions for the given content.

Parameters

ContentInfo $contentInfo

Return Value

VersionInfo[] an array of {@link \eZ\Publish\API\Repository\Values\Content\VersionInfo} sorted by creation date

Exceptions

UnauthorizedException if the user is not allowed to list versions

at line 299
public Content copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, VersionInfo $versionInfo = null)

Copies the content to a new location.

If no version is given, all versions are copied, otherwise only the given version.

Parameters

ContentInfo $contentInfo
LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to
VersionInfo $versionInfo

Return Value

Content

Exceptions

UnauthorizedException if the user is not allowed to copy the content to the given location

at line 310
public Relation[] loadRelations(VersionInfo $versionInfo)

Loads all outgoing relations for the given version.

Parameters

VersionInfo $versionInfo

Return Value

Relation[]

Exceptions

UnauthorizedException if the user is not allowed to read this version

at line 323
public Relation[] loadReverseRelations(ContentInfo $contentInfo)

Loads all incoming relations for a content object.

The relations come only from published versions of the source content objects

Parameters

ContentInfo $contentInfo

Return Value

Relation[]

Exceptions

UnauthorizedException if the user is not allowed to read this version

at line 339
public Relation addRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent)

Adds a relation of type common.

The source of the relation is the content and version referenced by $versionInfo.

Parameters

VersionInfo $sourceVersion
ContentInfo $destinationContent the destination of the relation

Return Value

Relation the newly created relation

Exceptions

UnauthorizedException if the user is not allowed to edit this version
BadStateException if the version is not a draft

at line 351
public deleteRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent)

Removes a relation of type COMMON from a draft.

Parameters

VersionInfo $sourceVersion
ContentInfo $destinationContent

Exceptions

UnauthorizedException if the user is not allowed edit this version
BadStateException if the version is not a draft
InvalidArgumentException if there is no relation of type COMMON for the given destination

at line 373
public removeTranslation(ContentInfo $contentInfo, string $languageCode)

Remove Content Object translation from all Versions (including archived ones) of a Content Object.

NOTE: this operation is risky and permanent, so user interface (ideally CLI) should provide a warning before performing it.

Parameters

ContentInfo $contentInfo
string $languageCode

Exceptions

BadStateException if the specified translation is the only one a Version has or it is the main translation of a Content Object.
UnauthorizedException if the user is not allowed to delete the content (in one of the locations of the given Content Object).
InvalidArgumentException if languageCode argument is invalid for the given content.

at line 392
public deleteTranslation(ContentInfo $contentInfo, string $languageCode)

Delete Content item Translation from all Versions (including archived ones) of a Content Object.

NOTE: this operation is risky and permanent, so user interface should provide a warning before performing it.

Parameters

ContentInfo $contentInfo
string $languageCode

Exceptions

BadStateException if the specified Translation is the Main Translation of a Content Item.
UnauthorizedException if the user is not allowed to delete the content (in one of the locations of the given Content Item).
InvalidArgumentException if languageCode argument is invalid for the given content.

at line 412
public Content deleteTranslationFromDraft(VersionInfo $versionInfo, string $languageCode)

Delete specified Translation from a Content Draft.

Parameters

VersionInfo $versionInfo Content Version Draft
string $languageCode Language code of the Translation to be removed

Return Value

Content Content Draft w/o the specified Translation

Exceptions

BadStateException if the specified Translation is the only one the Content Draft has or it is the main Translation of a Content Object.
UnauthorizedException if the user is not allowed to edit the Content (in one of the locations of the given Content Object).
InvalidArgumentException if languageCode argument is invalid for the given Draft.
NotFoundException if specified Version was not found

at line 424
public ContentCreateStruct newContentCreateStruct(ContentType $contentType, string $mainLanguageCode)

Instantiates a new content create struct object.

alwaysAvailable is set to the ContentType's defaultAlwaysAvailable

Parameters

ContentType $contentType
string $mainLanguageCode

Return Value

ContentCreateStruct

at line 431
public ContentMetadataUpdateStruct newContentMetadataUpdateStruct()

Instantiates a new content meta data update struct.

at line 438
public ContentUpdateStruct newContentUpdateStruct()

Instantiates a new content update struct.

Return Value

ContentUpdateStruct