Copied!

ContentService

ContentService.php : 31

This class provides service methods for managing content.

Constants

publicDEFAULT_PAGE_SIZE

ContentService.php : 33
public mixed DEFAULT_PAGE_SIZE = 25

Methods

publicaddRelation()

ContentService.php : 484

Adds a relation of type common.

public addRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent) : Relation

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

Parameters

Name Type Default value Description
$sourceVersion VersionInfo - -
$destinationContent ContentInfo -

the destination of the relation

Return values

Relation

the newly created relation

Tags
Throws
UnauthorizedException

if the user is not allowed to edit this version

Throws
BadStateException

if the version is not a draft

publiccopyContent()

ContentService.php : 396

Copies the content to a new location. If no version is given, all versions are copied, otherwise only the given version.

public copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct[, VersionInfo $versionInfo = null ]) : Content

Parameters

Name Type Default value Description
$contentInfo ContentInfo - -
$destinationLocationCreateStruct LocationCreateStruct -

the target location where the content is copied to

$versionInfo VersionInfo null -

Return values

Content

Tags
Throws
UnauthorizedException

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

publiccount()

ContentService.php : 618

Count total number of items returned by {@see ContentService::find()} method.

public count(Filter $filter[, array<string|int, string> $languages = null ]) : int

Parameters

Name Type Default value Description
$filter Filter - -
$languages array<string|int, string> null

a list of language codes to be added as additional constraints. If skipped, by default, unless SiteAccessAware layer has been disabled, languages set for a SiteAccess in a current context will be used.

Return values

int

publiccountContentDrafts()

ContentService.php : 287

Counts drafts for a user.

public countContentDrafts([User $user = null ]) : int

If no user is given the number of drafts for the authenticated user are returned

Parameters

Name Type Default value Description
$user User null

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

Return values

int

The number of drafts (VersionInfo) owned by the given user

Tags
Throws
InvalidArgumentException

publiccountRelations()

ContentService.php : 431

Counts all outgoing relations for the given version.

public countRelations(VersionInfo $versionInfo) : int

Parameters

Name Type Default value Description
$versionInfo VersionInfo - -

Return values

int

Tags
Throws
InvalidArgumentException
Throws
BadStateException

publiccountReverseRelations()

ContentService.php : 440

Counts all incoming relations for the given content object.

public countReverseRelations(ContentInfo $contentInfo) : int

Parameters

Name Type Default value Description
$contentInfo ContentInfo - -

Return values

int

The number of reverse relations (Relation)

publiccreateContent()

ContentService.php : 225

Creates a new content draft assigned to the authenticated user.

public createContent(ContentCreateStruct $contentCreateStruct[, array<string|int, LocationCreateStruct$locationCreateStructs = [] ][, array<string|int, string>|null $fieldIdentifiersToValidate = null ]) : Content

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.

Parameters

Name Type Default value Description
$contentCreateStruct ContentCreateStruct - -
$locationCreateStructs array<string|int, LocationCreateStruct> []

an array of LocationCreateStruct for each location parent under which a location should be created for the content While optional, it's highly recommended to use Locations for content as a lot of features in the system is usually tied to the tree structure (including default Role policies).

$fieldIdentifiersToValidate array<string|int, string>|null null

List of field identifiers for partial validation or null for case of full validation. Empty identifiers array is equal to no validation.

Return values

Content

  • the newly created content draft
Tags
Throws
UnauthorizedException

if the user is not allowed to create the content in the given location

Throws
InvalidArgumentException

if there is a provided remote ID which exists in the system or multiple Locations are under the same parent or if the a field value is not accepted by the field type

Throws
ContentFieldValidationException

if a field in the $contentCreateStruct is not valid

Throws
ContentValidationException

if a required field is missing or is set to an empty value

publiccreateContentDraft()

ContentService.php : 269

Creates a draft from a published or archived version.

public createContentDraft(ContentInfo $contentInfo[, VersionInfo|null $versionInfo = null ][, User|null $creator = null ][, Language|null $language = null ]) : Content

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

Name Type Default value Description
$contentInfo ContentInfo - -
$versionInfo VersionInfo|null null -
$creator User|null null

Used as creator of the draft if given - otherwise uses current-user

$language Language|null null -

Return values

Content

  • the newly created content draft
Tags
Throws
UnauthorizedException

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

publicdeleteContent()

ContentService.php : 251

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

public deleteContent(ContentInfo $contentInfo) : array<string|int, int>

Parameters

Name Type Default value Description
$contentInfo ContentInfo - -

Return values

array<string|int, int>

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

Tags
Throws
UnauthorizedException

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

publicdeleteRelation()

ContentService.php : 496

Removes a relation of type COMMON from a draft.

public deleteRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent) : void

Parameters

Name Type Default value Description
$sourceVersion VersionInfo - -
$destinationContent ContentInfo - -
Tags
Throws
UnauthorizedException

if the user is not allowed edit this version

Throws
BadStateException

if the version is not a draft

Throws
InvalidArgumentException

if there is no relation of type COMMON for the given destination

publicdeleteTranslation()

ContentService.php : 515

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

public deleteTranslation(ContentInfo $contentInfo, string $languageCode) : void

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

Parameters

Name Type Default value Description
$contentInfo ContentInfo - -
$languageCode string - -
Tags
Throws
BadStateException

if the specified Translation is the Main Translation of a Content Item.

Throws
UnauthorizedException

if the user is not allowed to delete the content (in one of the locations of the given Content Item).

Throws
InvalidArgumentException

if languageCode argument is invalid for the given content.

publicdeleteTranslationFromDraft()

ContentService.php : 538

Delete specified Translation from a Content Draft.

public deleteTranslationFromDraft(VersionInfo $versionInfo, string $languageCode) : Content

When using together with ContentService::publishVersion() method, make sure to not provide deleted translation in translations array, as it is going to be copied again from published version.

Parameters

Name Type Default value Description
$versionInfo VersionInfo -

Content Version Draft

$languageCode string -

Language code of the Translation to be removed

Return values

Content

Content Draft w/o the specified Translation

Tags
Throws
BadStateException

if the specified Translation is the only one the Content Draft has or it is the main Translation of a Content Object.

Throws
UnauthorizedException

if the user is not allowed to edit the Content (in one of the locations of the given Content Object).

Throws
InvalidArgumentException

if languageCode argument is invalid for the given Draft.

Throws
NotFoundException

if specified Version was not found

publicdeleteVersion()

ContentService.php : 369

Removes the given version.

public deleteVersion(VersionInfo $versionInfo) : void

Parameters

Name Type Default value Description
$versionInfo VersionInfo - -
Tags
Throws
BadStateException

if the version is in published state or is a last version of Content in non draft state

Throws
UnauthorizedException

if the user is not allowed to remove this version

publicfind()

ContentService.php : 609

Fetch Content items from the Repository filtered by the given conditions.

public find(Filter $filter[, array<string|int, string> $languages = null ]) : ContentList

Parameters

Name Type Default value Description
$filter Filter - -
$languages array<string|int, string> null

a list of language codes to be added as additional constraints. If skipped, by default, unless SiteAccessAware layer has been disabled, languages set for a SiteAccess in a current context will be used.

Return values

ContentList

publichideContent()

ContentService.php : 550

Hides Content by making all the Locations appear hidden.

public hideContent(ContentInfo $contentInfo) : void

It does not persist hidden state on Location object itself.

Content hidden by this API can be revealed by revealContent API.

Parameters

Name Type Default value Description
$contentInfo ContentInfo - -
Tags
See
ContentService::revealContent()

publicloadContent()

ContentService.php : 165

Loads content in a version of the given content object.

public loadContent(mixed $contentId[, array<string|int, string> $languages = null ][, int|null $versionNo = null ][, bool $useAlwaysAvailable = true ]) : Content

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

Parameters

Name Type Default value Description
$contentId mixed - -
$languages array<string|int, string> null

A language priority, filters returned fields and is used as prioritized language code on returned value object. If not given all languages are returned.

$versionNo int|null null

the version number. If not given the current version is returned

$useAlwaysAvailable bool true

Add Main language to $languages if true (default) and if alwaysAvailable is true

Return values

Content

Tags
Throws
NotFoundException

if the content or version with the given id and languages does not exist

Throws
UnauthorizedException

If the user has no access to read content and in case of un-published content: read versions

publicloadContentByContentInfo()

ContentService.php : 133

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

public loadContentByContentInfo(ContentInfo $contentInfo[, array<string|int, mixed> $languages = null ][, int|null $versionNo = null ][, bool $useAlwaysAvailable = true ]) : Content

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

Parameters

Name Type Default value Description
$contentInfo ContentInfo - -
$languages array<string|int, mixed> null

A language priority, filters returned fields and is used as prioritized language code on returned value object. If not given all languages are returned.

$versionNo int|null null

the version number. If not given the current version is returned from $contentInfo

$useAlwaysAvailable bool true

Add Main language to $languages if true (default) and if alwaysAvailable is true

Return values

Content

Tags
Throws
NotFoundException
  • if version with the given number does not exist
Throws
UnauthorizedException

if the user is not allowed to load this version

publicloadContentByRemoteId()

ContentService.php : 183

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

public loadContentByRemoteId(string $remoteId[, array<string|int, string> $languages = null ][, int|null $versionNo = null ][, bool $useAlwaysAvailable = true ]) : Content

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

Parameters

Name Type Default value Description
$remoteId string - -
$languages array<string|int, string> null

A language priority, filters returned fields and is used as prioritized language code on returned value object. If not given all languages are returned.

$versionNo int|null null

the version number. If not given the current version is returned

$useAlwaysAvailable bool true

Add Main language to $languages if true (default) and if alwaysAvailable is true

Return values

Content

Tags
Throws
NotFoundException
  • if the content or version with the given remote id does not exist
Throws
UnauthorizedException

If the user has no access to read content and in case of un-published content: read versions

publicloadContentByVersionInfo()

ContentService.php : 147

Loads content in the version given by version info.

public loadContentByVersionInfo(VersionInfo $versionInfo[, array<string|int, string> $languages = null ][, bool $useAlwaysAvailable = true ]) : Content

Parameters

Name Type Default value Description
$versionInfo VersionInfo - -
$languages array<string|int, string> null

A language priority, filters returned fields and is used as prioritized language code on returned value object. If not given all languages are returned.

$useAlwaysAvailable bool true

Add Main language to $languages if true (default) and if alwaysAvailable is true

Return values

Content

Tags
Throws
UnauthorizedException

if the user is not allowed to load this version

publicloadContentDraftList()

ContentService.php : 317

Loads drafts for a user when content is not in the trash. The list is sorted by modification date.

public loadContentDraftList([User|null $user = null ][, int $offset = 0 ][, int $limit = -1 ]) : ContentDraftList

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

Parameters

Name Type Default value Description
$user User|null null

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

$offset int 0 -
$limit int -1 -

Return values

ContentDraftList

publicloadContentDrafts()

ContentService.php : 302

Loads drafts for a user.

public loadContentDrafts([User $user = null ]) : array<string|int, VersionInfo>

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

Parameters

Name Type Default value Description
$user User null

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

Return values

array<string|int, VersionInfo>

the drafts (VersionInfo) owned by the given user

Tags
Deprecated

Please use ContentService::loadContentDraftList() instead to avoid risking loading too much data.

Throws
UnauthorizedException

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

publicloadContentInfo()

ContentService.php : 47

Loads a content info object.

public loadContentInfo(int $contentId) : ContentInfo

To load fields use loadContent

Parameters

Name Type Default value Description
$contentId int - -

Return values

ContentInfo

Tags
Throws
UnauthorizedException

if the user is not allowed to read the content

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

publicloadContentInfoByRemoteId()

ContentService.php : 72

Loads a content info object for the given remoteId.

public loadContentInfoByRemoteId(string $remoteId) : ContentInfo

To load fields use loadContent

Parameters

Name Type Default value Description
$remoteId string - -

Return values

ContentInfo

Tags
Throws
UnauthorizedException

if the user is not allowed to read the content

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

publicloadContentInfoList()

ContentService.php : 58

Bulk-load ContentInfo items by id's.

public loadContentInfoList(array<string|int, int> $contentIds) : array<string|int, ContentInfo>

Note: It does not throw exceptions on load, just skips erroneous (NotFound or Unauthorized) ContentInfo items.

Parameters

Name Type Default value Description
$contentIds array<string|int, int> - -

Return values

array<string|int, ContentInfo>

list of ContentInfo with Content Ids as keys

publicloadContentListByContentInfo()

ContentService.php : 200

Bulk-load Content items by the list of ContentInfo Value Objects.

public loadContentListByContentInfo(array<string|int, ContentInfo$contentInfoList[, array<string|int, string> $languages = [] ][, bool $useAlwaysAvailable = true ]) : array<string|int, Content>

Note: it does not throw exceptions on load, just ignores erroneous Content item. Moreover, since the method works on pre-loaded ContentInfo list, it is assumed that user is allowed to access every Content on the list.

Parameters

Name Type Default value Description
$contentInfoList array<string|int, ContentInfo> - -
$languages array<string|int, string> []

A language priority, filters returned fields and is used as prioritized language code on returned value object. If not given all languages are returned.

$useAlwaysAvailable bool true

Add Main language to $languages if true (default) and if alwaysAvailable is true, unless all languages have been asked for.

Return values

array<string|int, Content>

list of Content items with Content Ids as keys

publicloadRelationList()

ContentService.php : 419

Loads all outgoing relations for the given version.

public loadRelationList(VersionInfo $versionInfo[, int $offset = 0 ][, int $limit = self::DEFAULT_PAGE_SIZE ]) : RelationList

If the user is not allowed to read specific version then a returned RelationList will contain UnauthorizedRelationListItem

Parameters

Name Type Default value Description
$versionInfo VersionInfo - -
$offset int 0 -
$limit int ContentService::DEFAULT_PAGE_SIZE -

Return values

RelationList

Tags
Throws
InvalidArgumentException
Throws
BadStateException
See
UnauthorizedRelationListItem

publicloadRelations()

ContentService.php : 407

Loads all outgoing relations for the given version.

public loadRelations(VersionInfo $versionInfo) : array<string|int, Relation>

Parameters

Name Type Default value Description
$versionInfo VersionInfo - -

Return values

array<string|int, Relation>

Tags
Throws
UnauthorizedException

if the user is not allowed to read this version

Deprecated
4.5.7

The "ContentService::loadRelations()" method is deprecated, will be removed in 5.0.

publicloadReverseRelationList()

ContentService.php : 468

Loads all incoming relations for a content object.

public loadReverseRelationList(ContentInfo $contentInfo[, int $offset = 0 ][, int $limit = -1 ]) : RelationList

The relations come only from published versions of the source content objects. If the user is not allowed to read specific version then UnauthorizedRelationListItem is returned UnauthorizedRelationListItem

Parameters

Name Type Default value Description
$contentInfo ContentInfo - -
$offset int 0 -
$limit int -1 -

Return values

RelationList

publicloadReverseRelations()

ContentService.php : 453

Loads all incoming relations for a content object.

public loadReverseRelations(ContentInfo $contentInfo) : array<string|int, Relation>

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

Parameters

Name Type Default value Description
$contentInfo ContentInfo - -

Return values

array<string|int, Relation>

Tags
Throws
UnauthorizedException

if the user is not allowed to read this version

publicloadVersionInfo()

ContentService.php : 87

Loads a version info of the given content object.

public loadVersionInfo(ContentInfo $contentInfo[, int|null $versionNo = null ]) : VersionInfo

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

Parameters

Name Type Default value Description
$contentInfo ContentInfo - -
$versionNo int|null null

the version number. If not given the current version is returned.

Return values

VersionInfo

Tags
Throws
NotFoundException
  • if the version with the given number does not exist
Throws
UnauthorizedException

if the user is not allowed to load this version

publicloadVersionInfoById()

ContentService.php : 102

Loads a version info of the given content object id.

public loadVersionInfoById(int $contentId[, int|null $versionNo = null ]) : VersionInfo

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

Parameters

Name Type Default value Description
$contentId int - -
$versionNo int|null null

the version number. If not given the current version is returned.

Return values

VersionInfo

Tags
Throws
NotFoundException
  • if the version with the given number does not exist
Throws
UnauthorizedException

if the user is not allowed to load this version

publicloadVersionInfoListByContentInfo()

ContentService.php : 115

Bulk-load VersionInfo items by the list of ContentInfo Value Objects.

public loadVersionInfoListByContentInfo(array<string|int, ContentInfo$contentInfoList) : array<int, VersionInfo>

Parameters

Name Type Default value Description
$contentInfoList array<string|int, ContentInfo> - -

Return values

array<int, VersionInfo>

List of VersionInfo items with Content Ids as keys

Tags
Throws
BadStateException
Throws
InvalidArgumentException
Throws
NotFoundException

publicloadVersions()

ContentService.php : 382

Loads all versions for the given content.

public loadVersions(ContentInfo $contentInfo[, int|null $status = null ]) : array<string|int, VersionInfo>

Parameters

Name Type Default value Description
$contentInfo ContentInfo - -
$status int|null null -

Return values

array<string|int, VersionInfo>

an array of VersionInfo sorted by creation date

Tags
Throws
UnauthorizedException

if the user is not allowed to list versions

Throws
InvalidArgumentException

if the given status is invalid

publicnewContentCreateStruct()

ContentService.php : 572

Instantiates a new content create struct object.

public newContentCreateStruct(ContentType $contentType, string $mainLanguageCode) : ContentCreateStruct

alwaysAvailable is set to the ContentType's defaultAlwaysAvailable

Parameters

Name Type Default value Description
$contentType ContentType - -
$mainLanguageCode string - -

Return values

ContentCreateStruct

publicnewContentMetadataUpdateStruct()

ContentService.php : 579

Instantiates a new content meta data update struct.

public newContentMetadataUpdateStruct() : ContentMetadataUpdateStruct

Return values

ContentMetadataUpdateStruct

publicnewContentUpdateStruct()

ContentService.php : 586

Instantiates a new content update struct.

public newContentUpdateStruct() : ContentUpdateStruct

Return values

ContentUpdateStruct

publicpublishVersion()

ContentService.php : 358

Publishes a content version.

public publishVersion(VersionInfo $versionInfo[, array<string|int, string> $translations = Language::ALL ]) : Content

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

Name Type Default value Description
$versionInfo VersionInfo - -
$translations array<string|int, string> Language::ALL

List of language codes of translations which will be included in a published version. By default all translations from the current version will be published. If the list is provided but does not cover all currently published translations, the missing ones will be copied from the currently published version, overriding those in the current version.

Return values

Content

Tags
Throws
UnauthorizedException

if the user is not allowed to publish this version

Throws
BadStateException

if the version is not a draft

publicrevealContent()

ContentService.php : 560

Reveals Content hidden by hideContent API.

public revealContent(ContentInfo $contentInfo) : void

Locations which were hidden before hiding Content will remain hidden.

Parameters

Name Type Default value Description
$contentInfo ContentInfo - -
Tags
See
ContentService::hideContent()

publicupdateContent()

ContentService.php : 335

Updates the fields of a draft.

public updateContent(VersionInfo $versionInfo, ContentUpdateStruct $contentUpdateStruct[, array<string|int, string>|null $fieldIdentifiersToValidate = null ]) : Content

Parameters

Name Type Default value Description
$versionInfo VersionInfo - -
$contentUpdateStruct ContentUpdateStruct - -
$fieldIdentifiersToValidate array<string|int, string>|null null

List of field identifiers for partial validation or null for case of full validation. Empty identifiers array is equal to no validation.

Return values

Content

the content draft with the updated fields

Tags
Throws
UnauthorizedException

if the user is not allowed to update this version

Throws
BadStateException

if the version is not a draft

Throws
ContentFieldValidationException

if a field in the $contentUpdateStruct is not valid

Throws
ContentValidationException

if a required field is set to an empty value

Throws
InvalidArgumentException

if a field value is not accepted by the field type

publicupdateContentMetadata()

ContentService.php : 240

Updates the metadata.

public updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) : Content

See ContentMetadataUpdateStruct of a content object - to update fields use updateContent

Parameters

Name Type Default value Description
$contentInfo ContentInfo - -
$contentMetadataUpdateStruct ContentMetadataUpdateStruct - -

Return values

Content

the content with the updated attributes

Tags
Throws
UnauthorizedException

if the user is not allowed to update the content meta data

Throws
InvalidArgumentException

if the remoteId in $contentMetadataUpdateStruct is set but already exists

publicvalidate()

ContentService.php : 600

Validates given content related ValueObject returning field errors structure as a result.

public validate(ValueObject $object, array<string|int, mixed> $context[, array<string|int, string>|null $fieldIdentifiersToValidate = null ]) : array<string|int, mixed>

Parameters

Name Type Default value Description
$object ValueObject - -
$context array<string|int, mixed> -

Additional context parameters to be used by validators.

$fieldIdentifiersToValidate array<string|int, string>|null null

List of field identifiers for partial validation or null for case of full validation. Empty identifiers array is equal to no validation.

Return values

array<string|int, mixed>

Validation errors grouped by field definition and language code, in format: $returnValue[string|int $fieldDefinitionId][string $languageCode] = $fieldErrors;

Tags
Throws
InvalidArgumentException