Class

eZ\Publish\Core\Repository\ContentService

class ContentService implements ContentService

This class provides service methods for managing content.

Methods

__construct(Repository $repository, Handler $handler, DomainMapper $domainMapper, RelationProcessor $relationProcessor, NameSchemaService $nameSchemaService, FieldTypeRegistry $fieldTypeRegistry, array $settings = array())

Setups service with reference to repository object that created it & corresponding handler.

ContentInfo loadContentInfo(int $contentId)

Loads a content info object.

ContentInfo internalLoadContentInfo(mixed $id, bool $isRemoteId = false)

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 internalLoadContent(mixed $id, array $languages = null, int|null $versionNo = null, bool $isRemoteId = false, 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 97
public __construct(Repository $repository, Handler $handler, DomainMapper $domainMapper, RelationProcessor $relationProcessor, NameSchemaService $nameSchemaService, FieldTypeRegistry $fieldTypeRegistry, array $settings = array())

Setups service with reference to repository object that created it & corresponding handler.

Parameters

Repository $repository
Handler $handler
DomainMapper $domainMapper
RelationProcessor $relationProcessor
NameSchemaService $nameSchemaService
FieldTypeRegistry $fieldTypeRegistry
array $settings

at line 131
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 153
public ContentInfo internalLoadContentInfo(mixed $id, bool $isRemoteId = false)

Loads a content info object.

To load fields use loadContent

Parameters

mixed $id
bool $isRemoteId

Return Value

ContentInfo

Exceptions

NotFoundException
  • if the content with the given id does not exist

at line 182
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 206
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 224
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 264
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 287
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 305
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 339
public Content internalLoadContent(mixed $id, array $languages = null, int|null $versionNo = null, bool $isRemoteId = false, 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 $id
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|null $versionNo the version number. If not given the current version is returned
bool $isRemoteId
bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true

Return Value

Content

at line 413
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 filter for fields. 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 456
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 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 the provided remoteId exists in the system, required properties on struct are missing or invalid, or if multiple locations are under the same parent.
ContentFieldValidationException if a field in the $contentCreateStruct is not valid, or if a required field is missing / set to an empty value.
ContentValidationException If field definition does not exist in the ContentType, or value is set for non-translatable field in language other than main.

at line 834
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 963
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

Exceptions

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

at line 1005
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 if set given user is used to create the draft - otherwise the current-user is used

Return Value

Content
  • the newly created content draft

Exceptions

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

at line 1079
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 1121
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
InvalidArgumentException if a property on the struct is invalid.
ContentFieldValidationException if a field in the $contentCreateStruct is not valid, or if a required field is missing / set to an empty value.
ContentValidationException If field definition does not exist in the ContentType, or value is set for non-translatable field in language other than main.

at line 1388
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, but might be moved to be a param of ContentType in the future.

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 1480
public deleteVersion(VersionInfo $versionInfo)

Removes the given version.

Parameters

VersionInfo $versionInfo

Exceptions

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

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

Loads all versions for the given content.

Parameters

ContentInfo $contentInfo

Return Value

VersionInfo[] Sorted by creation date

Exceptions

UnauthorizedException if the user is not allowed to list versions

at line 1565
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 1625
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 1672
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 1713
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 1765
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 1819
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 1845
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 1941
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 2013
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 2029
public ContentMetadataUpdateStruct newContentMetadataUpdateStruct()

Instantiates a new content meta data update struct.

at line 2039
public ContentUpdateStruct newContentUpdateStruct()

Instantiates a new content update struct.

Return Value

ContentUpdateStruct