Class

eZ\Publish\Core\Repository\ContentTypeService

class ContentTypeService implements ContentTypeService

Methods

__construct(Repository $repository, Handler $contentTypeHandler, DomainMapper $domainMapper, ContentTypeDomainMapper $contentTypeDomainMapper, FieldTypeRegistry $fieldTypeRegistry, array $settings = array())

Setups service with reference to repository object that created it & corresponding handler.

ContentTypeGroup createContentTypeGroup(ContentTypeGroupCreateStruct $contentTypeGroupCreateStruct)

Create a Content Type Group object.

ContentTypeGroup loadContentTypeGroup(mixed $contentTypeGroupId, array $prioritizedLanguages = array())

Get a Content Type Group object by id.

ContentTypeGroup loadContentTypeGroupByIdentifier(string $contentTypeGroupIdentifier, array $prioritizedLanguages = array())

Get a Content Type Group object by identifier.

ContentTypeGroup[] loadContentTypeGroups(array $prioritizedLanguages = array())

Get all Content Type Groups.

updateContentTypeGroup(ContentTypeGroup $contentTypeGroup, ContentTypeGroupUpdateStruct $contentTypeGroupUpdateStruct)

Update a Content Type Group object.

deleteContentTypeGroup(ContentTypeGroup $contentTypeGroup)

Delete a Content Type Group.

ContentTypeDraft createContentType(ContentTypeCreateStruct $contentTypeCreateStruct, array $contentTypeGroups)

Create a Content Type object.

ContentType loadContentType(mixed $contentTypeId, array $prioritizedLanguages = array())

Get a Content Type object by id.

ContentType loadContentTypeByIdentifier(string $identifier, array $prioritizedLanguages = array())

Get a Content Type object by identifier.

ContentType loadContentTypeByRemoteId(string $remoteId, array $prioritizedLanguages = array())

Get a Content Type object by id.

ContentTypeDraft loadContentTypeDraft(mixed $contentTypeId)

Get a Content Type object draft by id.

ContentType[] loadContentTypes(ContentTypeGroup $contentTypeGroup, array $prioritizedLanguages = array())

Get Content Type objects which belong to the given content type group.

ContentTypeDraft createContentTypeDraft(ContentType $contentType)

Creates a draft from an existing content type.

updateContentTypeDraft(ContentTypeDraft $contentTypeDraft, ContentTypeUpdateStruct $contentTypeUpdateStruct)

Update a Content Type object.

deleteContentType(ContentType $contentType)

Delete a Content Type object.

ContentType copyContentType(ContentType $contentType, User $creator = null)

Copy Type incl fields and groupIds to a new Type object.

assignContentTypeGroup(ContentType $contentType, ContentTypeGroup $contentTypeGroup)

Assigns a content type to a content type group.

unassignContentTypeGroup(ContentType $contentType, ContentTypeGroup $contentTypeGroup)

Unassign a content type from a group.

addFieldDefinition(ContentTypeDraft $contentTypeDraft, FieldDefinitionCreateStruct $fieldDefinitionCreateStruct)

Adds a new field definition to an existing content type.

removeFieldDefinition(ContentTypeDraft $contentTypeDraft, FieldDefinition $fieldDefinition)

Remove a field definition from an existing Type.

updateFieldDefinition(ContentTypeDraft $contentTypeDraft, FieldDefinition $fieldDefinition, FieldDefinitionUpdateStruct $fieldDefinitionUpdateStruct)

Update a field definition.

publishContentTypeDraft(ContentTypeDraft $contentTypeDraft)

Publish the content type and update content objects.

ContentTypeGroupCreateStruct newContentTypeGroupCreateStruct(string $identifier)

Instantiates a new content type group create class.

ContentTypeCreateStruct newContentTypeCreateStruct(string $identifier)

Instantiates a new content type create class.

ContentTypeUpdateStruct newContentTypeUpdateStruct()

Instantiates a new content type update struct.

ContentTypeGroupUpdateStruct newContentTypeGroupUpdateStruct()

Instantiates a new content type update struct.

FieldDefinitionCreateStruct newFieldDefinitionCreateStruct($identifier, $fieldTypeIdentifier)

Instantiates a field definition create struct.

FieldDefinitionUpdateStruct newFieldDefinitionUpdateStruct()

Instantiates a field definition update class.

bool isContentTypeUsed(ContentType $contentType)

Returns true if the given content type $contentType has content instances.

Details

at line 88
public __construct(Repository $repository, Handler $contentTypeHandler, DomainMapper $domainMapper, ContentTypeDomainMapper $contentTypeDomainMapper, FieldTypeRegistry $fieldTypeRegistry, array $settings = array())

Setups service with reference to repository object that created it & corresponding handler.

Parameters

Repository $repository
Handler $contentTypeHandler
DomainMapper $domainMapper
ContentTypeDomainMapper $contentTypeDomainMapper
FieldTypeRegistry $fieldTypeRegistry
array $settings

at line 117
public ContentTypeGroup createContentTypeGroup(ContentTypeGroupCreateStruct $contentTypeGroupCreateStruct)

Create a Content Type Group object.

Parameters

ContentTypeGroupCreateStruct $contentTypeGroupCreateStruct

Return Value

ContentTypeGroup

Exceptions

UnauthorizedException if the user is not allowed to create a content type group
InvalidArgumentException If a group with the same identifier already exists

at line 173
public ContentTypeGroup loadContentTypeGroup(mixed $contentTypeGroupId, array $prioritizedLanguages = array())

Get a Content Type Group object by id.

Parameters

mixed $contentTypeGroupId
array $prioritizedLanguages Used as prioritized language code on translated properties of returned object.

Return Value

ContentTypeGroup

Exceptions

NotFoundException If group can not be found

at line 185
public ContentTypeGroup loadContentTypeGroupByIdentifier(string $contentTypeGroupIdentifier, array $prioritizedLanguages = array())

Get a Content Type Group object by identifier.

Parameters

string $contentTypeGroupIdentifier
array $prioritizedLanguages Used as prioritized language code on translated properties of returned object.

Return Value

ContentTypeGroup

Exceptions

NotFoundException If group can not be found

at line 201
public ContentTypeGroup[] loadContentTypeGroups(array $prioritizedLanguages = array())

Get all Content Type Groups.

Parameters

array $prioritizedLanguages Used as prioritized language code on translated properties of returned object.

Return Value

ContentTypeGroup[]

at line 222
public updateContentTypeGroup(ContentTypeGroup $contentTypeGroup, ContentTypeGroupUpdateStruct $contentTypeGroupUpdateStruct)

Update a Content Type Group object.

Parameters

ContentTypeGroup $contentTypeGroup the content type group to be updated
ContentTypeGroupUpdateStruct $contentTypeGroupUpdateStruct

Exceptions

UnauthorizedException if the user is not allowed to create a content type group
InvalidArgumentException If the given identifier (if set) already exists

at line 285
public deleteContentTypeGroup(ContentTypeGroup $contentTypeGroup)

Delete a Content Type Group.

This method only deletes an content type group which has content types without any content instances

Parameters

ContentTypeGroup $contentTypeGroup

Exceptions

UnauthorizedException if the user is not allowed to delete a content type group
InvalidArgumentException If a to be deleted content type has instances

at line 642
public ContentTypeDraft createContentType(ContentTypeCreateStruct $contentTypeCreateStruct, array $contentTypeGroups)

Create a Content Type object.

The content type is created in the state STATUS_DRAFT.

Parameters

ContentTypeCreateStruct $contentTypeCreateStruct
array $contentTypeGroups Required array of {@link APIContentTypeGroup} to link type with (must contain one)

Return Value

ContentTypeDraft

Exceptions

UnauthorizedException if the user is not allowed to create a content type
InvalidArgumentException In case when - array of content type groups does not contain at least one content type group - identifier or remoteId in the content type create struct already exists - there is a duplicate field identifier in the content type create struct
ContentTypeFieldDefinitionValidationException if a field definition in the $contentTypeCreateStruct is not valid
ContentTypeValidationException if a multiple field definitions of a same singular type are given

at line 846
public ContentType loadContentType(mixed $contentTypeId, array $prioritizedLanguages = array())

Get a Content Type object by id.

Parameters

mixed $contentTypeId
array $prioritizedLanguages Used as prioritized language code on translated properties of returned object.

Return Value

ContentType

Exceptions

NotFoundException If a content type with the given id and status DEFINED can not be found

at line 862
public ContentType loadContentTypeByIdentifier(string $identifier, array $prioritizedLanguages = array())

Get a Content Type object by identifier.

Parameters

string $identifier
array $prioritizedLanguages Used as prioritized language code on translated properties of returned object.

Return Value

ContentType

Exceptions

NotFoundException If content type with the given identifier and status DEFINED can not be found

at line 881
public ContentType loadContentTypeByRemoteId(string $remoteId, array $prioritizedLanguages = array())

Get a Content Type object by id.

Parameters

string $remoteId
array $prioritizedLanguages Used as prioritized language code on translated properties of returned object.

Return Value

ContentType

Exceptions

NotFoundException If content type with the given remote id and status DEFINED can not be found

at line 902
public ContentTypeDraft loadContentTypeDraft(mixed $contentTypeId)

Get a Content Type object draft by id.

Parameters

mixed $contentTypeId

Return Value

ContentTypeDraft

Exceptions

NotFoundException If the content type draft owned by the current user can not be found

at line 919
public ContentType[] loadContentTypes(ContentTypeGroup $contentTypeGroup, array $prioritizedLanguages = array())

Get Content Type objects which belong to the given content type group.

Parameters

ContentTypeGroup $contentTypeGroup
array $prioritizedLanguages Used as prioritized language code on translated properties of returned object.

Return Value

ContentType[] an array of {@link ContentType} which have status DEFINED

at line 950
public ContentTypeDraft createContentTypeDraft(ContentType $contentType)

Creates a draft from an existing content type.

This is a complete copy of the content type which has the state STATUS_DRAFT.

Parameters

ContentType $contentType

Return Value

ContentTypeDraft

Exceptions

UnauthorizedException if the user is not allowed to edit a content type
BadStateException If there is already a draft assigned to another user

at line 995
public updateContentTypeDraft(ContentTypeDraft $contentTypeDraft, ContentTypeUpdateStruct $contentTypeUpdateStruct)

Update a Content Type object.

Does not update fields (fieldDefinitions), use {@link updateFieldDefinition()} to update them.

Parameters

ContentTypeDraft $contentTypeDraft
ContentTypeUpdateStruct $contentTypeUpdateStruct

Exceptions

UnauthorizedException if the user is not allowed to update a content type
InvalidArgumentException If the given identifier or remoteId already exists or there is no draft assigned to the authenticated user

at line 1069
public deleteContentType(ContentType $contentType)

Delete a Content Type object.

Deletes a content type if it has no instances. If content type in state STATUSDRAFT is given, only the draft content type will be deleted. Otherwise, if content type in state STATUSDEFINED is given, all content type data will be deleted.

Parameters

ContentType $contentType

Exceptions

BadStateException If there exist content objects of this type
UnauthorizedException if the user is not allowed to delete a content type

at line 1109
public ContentType copyContentType(ContentType $contentType, User $creator = null)

Copy Type incl fields and groupIds to a new Type object.

New Type will have $creator as creator / modifier, created / modified should be updated with current time, updated remoteId and identifier should be appended with '_' + unique string.

Parameters

ContentType $contentType
User $creator if null the current-user is used

Return Value

ContentType

Exceptions

UnauthorizedException if the current-user is not allowed to copy a content type

at line 1144
public assignContentTypeGroup(ContentType $contentType, ContentTypeGroup $contentTypeGroup)

Assigns a content type to a content type group.

Parameters

ContentType $contentType
ContentTypeGroup $contentTypeGroup

Exceptions

UnauthorizedException if the user is not allowed to unlink a content type
InvalidArgumentException If the content type is already assigned the given group

at line 1186
public unassignContentTypeGroup(ContentType $contentType, ContentTypeGroup $contentTypeGroup)

Unassign a content type from a group.

Parameters

ContentType $contentType
ContentTypeGroup $contentTypeGroup

Exceptions

UnauthorizedException if the user is not allowed to link a content type
InvalidArgumentException If the content type is not assigned this the given group.
BadStateException If $contentTypeGroup is the last group assigned to the content type

at line 1242
public addFieldDefinition(ContentTypeDraft $contentTypeDraft, FieldDefinitionCreateStruct $fieldDefinitionCreateStruct)

Adds a new field definition to an existing content type.

The content type must be in state DRAFT.

Parameters

ContentTypeDraft $contentTypeDraft
FieldDefinitionCreateStruct $fieldDefinitionCreateStruct

Exceptions

InvalidArgumentException if the identifier in already exists in the content type
UnauthorizedException if the user is not allowed to edit a content type
ContentTypeFieldDefinitionValidationException if a field definition in the $contentTypeCreateStruct is not valid
BadStateException If field definition of the same non-repeatable type is being added to the ContentType that already contains one or field definition that can't be added to a ContentType that has Content instances is being added to such ContentType

at line 1315
public removeFieldDefinition(ContentTypeDraft $contentTypeDraft, FieldDefinition $fieldDefinition)

Remove a field definition from an existing Type.

Parameters

ContentTypeDraft $contentTypeDraft
FieldDefinition $fieldDefinition

Exceptions

InvalidArgumentException If the given field definition does not belong to the given type
UnauthorizedException if the user is not allowed to edit a content type

at line 1359
public updateFieldDefinition(ContentTypeDraft $contentTypeDraft, FieldDefinition $fieldDefinition, FieldDefinitionUpdateStruct $fieldDefinitionUpdateStruct)

Update a field definition.

Parameters

ContentTypeDraft $contentTypeDraft the content type draft
FieldDefinition $fieldDefinition the field definition which should be updated
FieldDefinitionUpdateStruct $fieldDefinitionUpdateStruct

Exceptions

InvalidArgumentException If the field id in the update struct is not found or does not belong to the content type If the given identifier is used in an existing field of the given content type
UnauthorizedException if the user is not allowed to edit a content type

at line 1414
public publishContentTypeDraft(ContentTypeDraft $contentTypeDraft)

Publish the content type and update content objects.

This method updates content objects, depending on the changed field definitions.

Parameters

ContentTypeDraft $contentTypeDraft

Exceptions

BadStateException If the content type has no draft
InvalidArgumentException If the content type has no field definitions
UnauthorizedException if the user is not allowed to publish a content type

at line 1475
public ContentTypeGroupCreateStruct newContentTypeGroupCreateStruct(string $identifier)

Instantiates a new content type group create class.

Parameters

string $identifier

Return Value

ContentTypeGroupCreateStruct

Exceptions

InvalidArgumentValue if given identifier is not a string

at line 1497
public ContentTypeCreateStruct newContentTypeCreateStruct(string $identifier)

Instantiates a new content type create class.

Parameters

string $identifier

Return Value

ContentTypeCreateStruct

Exceptions

InvalidArgumentValue if given identifier is not a string

at line 1515
public ContentTypeUpdateStruct newContentTypeUpdateStruct()

Instantiates a new content type update struct.

at line 1525
public ContentTypeGroupUpdateStruct newContentTypeGroupUpdateStruct()

Instantiates a new content type update struct.

at line 1541
public FieldDefinitionCreateStruct newFieldDefinitionCreateStruct($identifier, $fieldTypeIdentifier)

Instantiates a field definition create struct.

Parameters

$identifier
$fieldTypeIdentifier

Return Value

FieldDefinitionCreateStruct

Exceptions

InvalidArgumentValue if given identifier is not a string or given fieldTypeIdentifier is not a string

at line 1564
public FieldDefinitionUpdateStruct newFieldDefinitionUpdateStruct()

Instantiates a field definition update class.

at line 1578
public bool isContentTypeUsed(ContentType $contentType)

Returns true if the given content type $contentType has content instances.

Parameters

ContentType $contentType

Return Value

bool