ContentService
This class provides service methods for managing content.
Constants¶
DEFAULT_PAGE_SIZE ¶
|
|
Methods¶
addRelation() ¶
Adds a relation of type common.
|
|
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
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 | - |
Return values
Tags
count() ¶
Count total number of items returned by {@see ContentService::find()} method.
|
|
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
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 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
- 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 | - |
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<string|int, int>
Affected Location Id's (List of Locations of the Content that was deleted)
Tags
deleteRelation() ¶
Removes a relation of type COMMON 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 w/o the specified Translation
Tags
deleteVersion() ¶
Removes the given version.
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$versionInfo | VersionInfo | - | - |
Tags
find() ¶
Fetch Content items from the Repository filtered by the given conditions.
|
|
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
hideContent() ¶
Hides Content by making all the Locations appear hidden.
|
|
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
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 | 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
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<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
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 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 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 |
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
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 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
loadContentListByContentInfo() ¶
Bulk-load Content items by the list of ContentInfo Value Objects.
|
|
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
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<string|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 UnauthorizedRelationListItem
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<string|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<string|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<string|int, VersionInfo>
an array of VersionInfo sorted by creation date
Tags
newContentCreateStruct() ¶
Instantiates a new content create struct object.
|
|
alwaysAvailable is set to the ContentType's 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<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
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<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 content draft with the updated fields
Tags
updateContentMetadata() ¶
Updates the metadata.
|
|
See ContentMetadataUpdateStruct of a content object - to update fields use 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<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;