eZ\Bundle\EzPublishCoreBundle\Features\Context\BasicContentContext::createContentDraft PHP Method

createContentDraft() public method

Creates a content draft.
public createContentDraft ( eZ\Publish\API\Repository\Values\Content\Location $parentLocationId, string $contentTypeIdentifier, array $fields, string $languageCode = null ) : eZ\Publish\API\Repository\Values\Content\Content
$parentLocationId eZ\Publish\API\Repository\Values\Content\Location
$contentTypeIdentifier string
$fields array Fields, as primitives understood by setField
$languageCode string
return eZ\Publish\API\Repository\Values\Content\Content an unpublished Content draft
    public function createContentDraft($parentLocationId, $contentTypeIdentifier, $fields, $languageCode = null)
    {
        $languageCode = $languageCode ?: self::DEFAULT_LANGUAGE;
        $repository = $this->getRepository();
        $locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct($parentLocationId);
        $contentTypeIdentifier = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
        $contentCreateStruct = $this->contentService->newContentCreateStruct($contentTypeIdentifier, $languageCode);
        foreach (array_keys($fields) as $key) {
            $contentCreateStruct->setField($key, $fields[$key]);
        }
        return $this->contentService->createContent($contentCreateStruct, array($locationCreateStruct));
    }