eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler::internalCreate PHP Method

internalCreate() protected method

Used by self::create(), self::createDraft() and self::copy()
protected internalCreate ( eZ\Publish\SPI\Persistence\Content\Type\CreateStruct $createStruct, mixed | null $contentTypeId = null ) : eZ\Publish\SPI\Persistence\Content\Type
$createStruct eZ\Publish\SPI\Persistence\Content\Type\CreateStruct
$contentTypeId mixed | null 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)) {
                throw new InvalidArgumentException('position', "'" . var_export($fieldDef->position, true) . "' is wrong value in class FieldDefinition, an integer 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;
    }