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 : 427

Adds a common relation.

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

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

Parameters

Name Type Default value Description
$sourceVersion VersionInfo -

The source content's version in relation with the destination.

$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.

See
Relation::COMMON

publiccopyContent()

ContentService.php : 348

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|null $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 null -

Return values

Content

Tags
Throws
UnauthorizedException

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

publiccount()

ContentService.php : 548

Gets the total number of fetchable Content items.

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

Counts total number of items returned by ContentService::find() with the same parameters.

Parameters

Name Type Default value Description
$filter Filter - -
$languages array<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 : 257

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 : 383

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 : 390

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 : 202

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 doesn't 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 : 239

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

If not set the draft is created with the initialLanguage code of the source version or if not present with the main language.

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 : 223

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

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

Parameters

Name Type Default value Description
$contentInfo ContentInfo - -

Return values

array<int, int>

Affected Location IDs (List of Location IDs 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 : 438

Removes a common relation 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 Relation::COMMON for the given destination.

See
Relation::COMMON

publicdeleteTranslation()

ContentService.php : 454

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 : 477

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 without 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 : 328

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 : 537

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

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

Parameters

Name Type Default value Description
$filter Filter - -
$languages array<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 : 488

Hides Content by making all the Locations appear hidden.

public hideContent(ContentInfo $contentInfo) : void

It doesn't persist hidden state on Location object itself.

Content hidden by this API can be revealed by ContentService::revealContent() API.

Parameters

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

publicloadContent()

ContentService.php : 144

Loads content in a version of the given content object.

public loadContent(int $contentId[, array<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 int - -
$languages array<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 ContentInfo::$alwaysAvailable is true.

Return values

Content

Tags
Throws
NotFoundException

if the content or version with the given id and languages doesn't exist.

Throws
UnauthorizedException

if the user lacks:

  • content/read permission for published content, or
  • content/read and content/versionread permissions for draft content.

publicloadContentByContentInfo()

ContentService.php : 116

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

public loadContentByContentInfo(ContentInfo $contentInfo[, array<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
$contentInfo ContentInfo - -
$languages array<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 from $contentInfo.

$useAlwaysAvailable bool true

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

Return values

Content

Tags
Throws
NotFoundException

if version with the given number doesn't exist.

Throws
UnauthorizedException

if the user is not allowed to load this version.

publicloadContentByRemoteId()

ContentService.php : 161

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 ContentInfo::$alwaysAvailable is true.

Return values

Content

Tags
Throws
NotFoundException

if the content or version with the given remote id doesn't exist.

Throws
UnauthorizedException

if the user lacks:

  • content/read permission for published content, or
  • content/read and content/versionread permissions for draft content.

publicloadContentByVersionInfo()

ContentService.php : 127

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 ContentInfo::$alwaysAvailable is true.

Return values

Content

Tags
Throws
UnauthorizedException

if the user is not allowed to load this version.

publicloadContentDraftList()

ContentService.php : 283

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 : 272

Loads drafts for a user.

public loadContentDrafts([User|null $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 null

The user to load drafts for. If null, the current user's drafts are loaded.

Return values

array<string|int, VersionInfo>

The drafts 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 : 43

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 doesn't exist.

publicloadContentInfoByRemoteId()

ContentService.php : 64

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 doesn't exist.

publicloadContentInfoList()

ContentService.php : 54

Bulk-load ContentInfo items by id's.

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

Note: It doesn't throw exceptions on load, just skips erroneous (NotFound or Unauthorized) ContentInfo items.

Parameters

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

Return values

array<int, ContentInfo>

List of ContentInfo with content ids as keys

publicloadContentListByContentInfo()

ContentService.php : 178

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

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

Note: it doesn't 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<int, ContentInfo> - -
$languages array<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 ContentInfo::$alwaysAvailable is true, unless all languages have been asked for.

Return values

array<int, Content>

List of Content items with Content Ids as keys

publicloadRelationList()

ContentService.php : 371

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 : 359

Loads all outgoing relations for the given version.

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

Parameters

Name Type Default value Description
$versionInfo VersionInfo - -

Return values

array<int, Relation>

Tags
Throws
UnauthorizedException

if the user is not allowed to read this version.

Deprecated
4.5.7

It will be removed in 5.0. Use ContentService::loadRelationList() instead.

publicloadReverseRelationList()

ContentService.php : 409

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

Parameters

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

Return values

RelationList

publicloadReverseRelations()

ContentService.php : 401

Loads all incoming relations for a content object.

public loadReverseRelations(ContentInfo $contentInfo) : array<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<int, Relation>

Tags
Throws
UnauthorizedException

if the user is not allowed to read this version.

publicloadVersionInfo()

ContentService.php : 76

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 doesn't exist.

Throws
UnauthorizedException

if the user is not allowed to load this version.

publicloadVersionInfoById()

ContentService.php : 88

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 doesn't exist.

Throws
UnauthorizedException

if the user is not allowed to load this version.

publicloadVersionInfoListByContentInfo()

ContentService.php : 101

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

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

Parameters

Name Type Default value Description
$contentInfoList array<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 : 338

Loads all versions for the given content.

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

Parameters

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

Return values

array<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 : 504

Instantiates a new content create struct object.

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

ContentCreateStruct::$alwaysAvailable is set to the ContentType::$defaultAlwaysAvailable.

Parameters

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

Return values

ContentCreateStruct

publicnewContentMetadataUpdateStruct()

ContentService.php : 509

Instantiates a new content meta data update struct.

public newContentMetadataUpdateStruct() : ContentMetadataUpdateStruct

Return values

ContentMetadataUpdateStruct

publicnewContentUpdateStruct()

ContentService.php : 514

Instantiates a new content update struct.

public newContentUpdateStruct() : ContentUpdateStruct

Return values

ContentUpdateStruct

publicpublishVersion()

ContentService.php : 319

Publishes a content version.

public publishVersion(VersionInfo $versionInfo[, array<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<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 doesn't 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 : 497

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 : 299

Updates the fields of a draft.

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

Parameters

Name Type Default value Description
$versionInfo VersionInfo - -
$contentUpdateStruct ContentUpdateStruct - -
$fieldIdentifiersToValidate array<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 : 214

Updates the metadata.

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

To update fields, use ContentService::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 metadata.

Throws
InvalidArgumentException

if the remoteId in $contentMetadataUpdateStruct is set but already exists.

publicvalidate()

ContentService.php : 528

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

public validate(ValueObject $object, array<string|int, mixed> $context[, array<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<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