ContentService
This class provides service methods for managing content.
Constants¶
DEFAULT_PAGE_SIZE ¶
|
|
Methods¶
addRelation() ¶
Adds a common 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
The newly created relation.
Tags
copyContent() ¶
Copies the content to a new location. If no version is given, all versions are copied, otherwise only the given version.
|
|
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
Tags
count() ¶
Gets the total number of fetchable Content items.
|
|
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
countContentDrafts() ¶
Counts drafts for a user.
|
|
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
countRelations() ¶
Counts all outgoing relations for the given version.
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$versionInfo | VersionInfo | - | - |
Return values
int
Tags
countReverseRelations() ¶
Counts all incoming relations for the given content object.
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$contentInfo | ContentInfo | - | - |
Return values
int
The number of reverse relations (Relation).
createContent() ¶
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 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
The newly created content draft.
Tags
createContentDraft() ¶
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
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
The newly created content draft.
Tags
deleteContent() ¶
Deletes a content object including all its versions and locations including their subtrees.
|
|
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
deleteRelation() ¶
Removes a common relation from a draft.
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$sourceVersion | VersionInfo | - | - |
$destinationContent | ContentInfo | - | - |
Tags
deleteTranslation() ¶
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
Name | Type | Default value | Description |
---|---|---|---|
$contentInfo | ContentInfo | - | - |
$languageCode | string | - | - |
Tags
deleteTranslationFromDraft() ¶
Delete specified Translation from a Content Draft.
|
|
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 Draft without the specified Translation.
Tags
deleteVersion() ¶
Removes the given version.
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$versionInfo | VersionInfo | - | - |
Tags
find() ¶
Fetches Content items from the Repository filtered by the given conditions.
|
|
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
hideContent() ¶
Hides Content by making all the Locations appear hidden.
|
|
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
loadContent() ¶
Loads content in a version of the given content object.
|
|
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
Tags
loadContentByContentInfo() ¶
Loads content in a version for the given content info object.
|
|
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
Tags
loadContentByRemoteId() ¶
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
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
Tags
loadContentByVersionInfo() ¶
Loads content in the version given by version info.
|
|
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
Tags
loadContentDraftList() ¶
Loads drafts for a user when content is not in the trash. The list is sorted by modification date.
|
|
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
loadContentDrafts() ¶
Loads drafts for a user.
|
|
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 |
Return values
array<string|int, VersionInfo>
The drafts owned by the given user.
Tags
loadContentInfo() ¶
Loads a content info object.
|
|
To load fields use loadContent
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$contentId | int | - | - |
Return values
Tags
loadContentInfoByRemoteId() ¶
Loads a content info object for the given remoteId.
|
|
To load fields use loadContent
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$remoteId | string | - | - |
Return values
Tags
loadContentInfoList() ¶
Bulk-load ContentInfo items by id's.
|
|
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
loadContentListByContentInfo() ¶
Bulk-load Content items by the list of ContentInfo Value Objects.
|
|
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
loadRelationList() ¶
Loads all outgoing relations for the given version.
|
|
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
Tags
loadRelations() ¶
Loads all outgoing relations for the given version.
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$versionInfo | VersionInfo | - | - |
Return values
array<int, Relation>
Tags
loadReverseRelationList() ¶
Loads all incoming relations for a content object.
|
|
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
loadReverseRelations() ¶
Loads all incoming relations for a content object.
|
|
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
loadVersionInfo() ¶
Loads a version info of the given content object.
|
|
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
Tags
loadVersionInfoById() ¶
Loads a version info of the given content object id.
|
|
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
Tags
loadVersionInfoListByContentInfo() ¶
Bulk-load VersionInfo items by the list of ContentInfo Value Objects.
|
|
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
loadVersions() ¶
Loads all versions for the given content.
|
|
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
newContentCreateStruct() ¶
Instantiates a new content create struct object.
|
|
ContentCreateStruct::$alwaysAvailable is set to the ContentType::$defaultAlwaysAvailable.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$contentType | ContentType | - | - |
$mainLanguageCode | string | - | - |
Return values
newContentMetadataUpdateStruct() ¶
Instantiates a new content meta data update struct.
|
|
Return values
newContentUpdateStruct() ¶
Instantiates a new content update struct.
|
|
Return values
publishVersion() ¶
Publishes a content version.
|
|
Publishes a content version and deletes archive versions if they overflow max archive versions. Max archive versions are currently a configuration for default max limit, by default set to 5.
Parameters
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
Tags
revealContent() ¶
Reveals Content hidden by hideContent API.
|
|
Locations which were hidden before hiding Content will remain hidden.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$contentInfo | ContentInfo | - | - |
Tags
updateContent() ¶
Updates the fields of a draft.
|
|
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
The content draft with the updated fields.
Tags
updateContentMetadata() ¶
Updates the metadata.
|
|
To update fields, use ContentService::updateContent().
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$contentInfo | ContentInfo | - | - |
$contentMetadataUpdateStruct | ContentMetadataUpdateStruct | - | - |
Return values
The content with the updated attributes.
Tags
validate() ¶
Validates given content related ValueObject returning field errors structure as a result.
|
|
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;