public function createDraft($contentTypeIdentifier, array $fields)
    {
        $contentService = $this->repository->getContentService();

        $createStruct = $contentService->newContentCreateStruct(
            $this->repository->getContentTypeService()->loadContentTypeByIdentifier($contentTypeIdentifier),
            'eng-GB'
        );

        foreach ($fields as $fieldDefIdentifier => $fieldValue) {
            $createStruct->setField($fieldDefIdentifier, $fieldValue);
        }

        $locationCreateStruct = $this->repository->getLocationService()->newLocationCreateStruct(2);

        $this->currentDraft = $this->repository->sudo(
            function () use ($createStruct, $locationCreateStruct) {
                return $this->repository->getContentService()->createContent(
                    $createStruct,
                    [$locationCreateStruct]
                );
            }
        );

        return $this->currentDraft;
    }
public function createDraft($contentTypeIdentifier, array $fields)
    {
        $contentService = $this->repository->getContentService();

        $createStruct = $contentService->newContentCreateStruct(
            $this->repository->getContentTypeService()->loadContentTypeByIdentifier($contentTypeIdentifier),
            'eng-GB'
        );

        foreach ($fields as $fieldDefIdentifier => $fieldValue) {
            $createStruct->setField($fieldDefIdentifier, $fieldValue);
        }

        $locationCreateStruct = $this->repository->getLocationService()->newLocationCreateStruct(2);

        $this->currentDraft = $this->repository->sudo(
            function () use ($createStruct, $locationCreateStruct) {
                return $this->repository->getContentService()->createContent(
                    $createStruct,
                    [$locationCreateStruct]
                );
            }
        );

        return $this->currentDraft;
    }
public function createDraft ( $ contentTypeIdentifier , array $ fields ) { $ contentService = $ this -> repository -> getContentService ( ) ; $ createStruct = $ contentService -> newContentCreateStruct ( $ this -> repository -> getContentTypeService ( ) -> loadContentTypeByIdentifier ( $ contentTypeIdentifier ) , 'eng-GB' ) ; foreach ( $ fields as $ fieldDefIdentifier => $ fieldValue ) { $ createStruct -> setField ( $ fieldDefIdentifier , $ fieldValue ) ; } $ locationCreateStruct = $ this -> repository -> getLocationService ( ) -> newLocationCreateStruct ( 2 ) ; $ this -> currentDraft = $ this -> repository -> sudo ( function ( ) use ( $ createStruct , $ locationCreateStruct ) { return $ this -> repository -> getContentService ( ) -> createContent ( $ createStruct , [ $ locationCreateStruct ] ) ; } ) ; return $ this -> currentDraft ; }
Uses a content type identifier + a hash of fields values
to create and publish a draft below the root location.

@param string $contentTypeIdentifier
@param array $fields Hash of field def identifier => field value

@return Content the created draft.
Uses a content type identifier + a hash of fields values to create and publish a draft below the root location .