Creates an update struct from an existing $type.
public createUpdateStructFromType ( eZ\Publish\SPI\Persistence\Content\Type $type ) : eZ\Publish\SPI\Persistence\Content\Type\UpdateStruct | ||
$type | eZ\Publish\SPI\Persistence\Content\Type | |
return | eZ\Publish\SPI\Persistence\Content\Type\UpdateStruct |
/** * @param mixed $userId * @param mixed $contentTypeId * @param int $status One of Type::STATUS_DEFINED|Type::STATUS_DRAFT|Type::STATUS_MODIFIED * * @return Type */ public function copy($userId, $contentTypeId, $status) { $createStruct = $this->mapper->createCreateStructFromType($this->load($contentTypeId, $status)); $createStruct->modifierId = $userId; $createStruct->created = $createStruct->modified = time(); $createStruct->creatorId = $userId; $createStruct->remoteId = md5(uniqid(get_class($createStruct), true)); // extract actual identifier name, without "copy_of_" and number $originalIdentifier = preg_replace('/^copy_of_(.+)_\\d+$/', '$1', $createStruct->identifier); // set temporary identifier $createStruct->identifier = $createStruct->remoteId; // Set FieldDefinition ids to null to trigger creating new id foreach ($createStruct->fieldDefinitions as $fieldDefinition) { $fieldDefinition->id = null; } $contentTypeCopy = $this->internalCreate($createStruct); $updateStruct = $this->mapper->createUpdateStructFromType($contentTypeCopy); $updateStruct->identifier = 'copy_of_' . $originalIdentifier . '_' . $contentTypeCopy->id; return $this->update($contentTypeCopy->id, $contentTypeCopy->status, $updateStruct); }