/** * Inserts a new content type. * * @param \eZ\Publish\SPI\Persistence\Content\Type $type * @param mixed|null $typeId * * @return mixed Type ID */ public function insertType(Type $type, $typeId = null) { try { return $this->innerGateway->insertType($type, $typeId); } catch (DBALException $e) { throw new RuntimeException('Database error', 0, $e); } catch (PDOException $e) { throw new RuntimeException('Database error', 0, $e); } }
/** * Internal method for creating ContentType * * Used by self::create(), self::createDraft() and self::copy() * * @param \eZ\Publish\SPI\Persistence\Content\Type\CreateStruct $createStruct * @param mixed|null $contentTypeId Used by self::createDraft() to retain ContentType id in the draft * * @return \eZ\Publish\SPI\Persistence\Content\Type */ protected function internalCreate( CreateStruct $createStruct, $contentTypeId = null ) { foreach ( $createStruct->fieldDefinitions as $fieldDef ) { if ( !is_int( $fieldDef->position ) || $fieldDef->position <= 0 ) throw new InvalidArgumentException( "position", "'" . var_export( $fieldDef->position, true ) . "' is wrong value in class FieldDefinition, an integer strictly greater than 0 is required." ); } $createStruct = clone $createStruct; $contentType = $this->mapper->createTypeFromCreateStruct( $createStruct ); $contentType->id = $this->contentTypeGateway->insertType( $contentType, $contentTypeId ); foreach ( $contentType->groupIds as $groupId ) { $this->contentTypeGateway->insertGroupAssignment( $groupId, $contentType->id, $contentType->status ); } foreach ( $contentType->fieldDefinitions as $fieldDef ) { $storageFieldDef = new StorageFieldDefinition(); $this->mapper->toStorageFieldDefinition( $fieldDef, $storageFieldDef ); $fieldDef->id = $this->contentTypeGateway->insertFieldDefinition( $contentType->id, $contentType->status, $fieldDef, $storageFieldDef ); } return $contentType; }