createCreateStructFromType() public method

Creates a create struct from an existing $type.
public createCreateStructFromType ( eZ\Publish\SPI\Persistence\Content\Type $type ) : eZ\Publish\SPI\Persistence\Content\Type\CreateStruct
$type eZ\Publish\SPI\Persistence\Content\Type
return eZ\Publish\SPI\Persistence\Content\Type\CreateStruct
 /**
  * @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));
     $createStruct->identifier = 'copy_of_' . $createStruct->identifier . '_' . $createStruct->remoteId;
     // Set FieldDefinition ids to null to trigger creating new id
     foreach ($createStruct->fieldDefinitions as $fieldDefinition) {
         $fieldDefinition->id = null;
     }
     return $this->internalCreate($createStruct);
 }
示例#2
0
 /**
  * @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);
 }
示例#3
0
 /**
  * @covers eZ\Publish\Core\Persistence\Legacy\Content\Type\Mapper::createCreateStructFromType
  *
  * @return void
  */
 public function testCreateStructFromType()
 {
     $type = $this->getContentTypeFixture();
     $mapper = new Mapper($this->getConverterRegistryMock());
     $struct = $mapper->createCreateStructFromType($type);
     // Iterate through struct, since it has fewer props
     foreach ($struct as $propName => $propVal) {
         $this->assertEquals($struct->{$propName}, $type->{$propName}, "Property \${$propName} not equal");
     }
 }