Class

eZ\Publish\Core\SignalSlot\ContentService

class ContentService implements ContentService

ContentService class.

Methods

__construct(ContentService $service, SignalDispatcher $signalDispatcher)

Constructor.

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(int $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 $user = null)

Creates a draft from a published or archived version.

VersionInfo[] loadContentDrafts(User $user = null)

Loads drafts for a user.

Content translateVersion(TranslationInfo $translationInfo, TranslationValues $translationValues, User $user = null)

Translate a version.

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.

addTranslationInfo(TranslationInfo $translationInfo)

Adds translation information to the content object.

TranslationInfo[] loadTranslationInfos(ContentInfo $contentInfo, array $filter = array())

lists the translations done on this content object.

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 65
public __construct(ContentService $service, SignalDispatcher $signalDispatcher)

Constructor.

Construct service object from aggregated service and signal dispatcher

Parameters

ContentService $service
SignalDispatcher $signalDispatcher

at line 83
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 100
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 118
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 136
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 156
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 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 version with the given number does not exist
UnauthorizedException if the user is not allowed to load this version

at line 172
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 filter for fields. 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 192
public Content loadContent(int $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

int $contentId
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 id and languages does not exist
UnauthorizedException if the user is not allowed to load this version

at line 212
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 is not allowed to load this version

at line 239
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 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 267
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 290
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 320
public Content createContentDraft(ContentInfo $contentInfo, VersionInfo $versionInfo = null, User $user = 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 $user 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 user is not allowed to create the draft

at line 347
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 user is not allowed to load the draft list

at line 372
public Content translateVersion(TranslationInfo $translationInfo, TranslationValues $translationValues, User $user = null)

Translate a version.

updates the destination version given in $translationInfo with the provided translated fields in $translationValues

Parameters

TranslationInfo $translationInfo
TranslationValues $translationValues
User $user If set, this user is taken as modifier of the version

Return Value

Content the content draft with the translated fields

Exceptions

UnauthorizedException if the user is not allowed to update this version
BadStateException if the given destination version is not a draft
ContentValidationException if a required field is set to an empty value
ContentFieldValidationException if a field in the $translationValues is not valid

at line 402
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 427
public Content publishVersion(VersionInfo $versionInfo)

Publishes a content version.

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 451
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 475
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 492
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 519
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 535
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 554
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 580
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 607
public addTranslationInfo(TranslationInfo $translationInfo)

Adds translation information to the content object.

Parameters

TranslationInfo $translationInfo

Exceptions

UnauthorizedException if the user is not allowed add a translation info

at line 631
public TranslationInfo[] loadTranslationInfos(ContentInfo $contentInfo, array $filter = array())

lists the translations done on this content object.

Parameters

ContentInfo $contentInfo
array $filter

Return Value

TranslationInfo[]

Exceptions

UnauthorizedException if the user is not allowed read translation infos

at line 639
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 665
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 694
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 709
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 719
public ContentMetadataUpdateStruct newContentMetadataUpdateStruct()

Instantiates a new content meta data update struct.

at line 729
public ContentUpdateStruct newContentUpdateStruct()

Instantiates a new content update struct.

Return Value

ContentUpdateStruct