eZ\Bundle\EzPublishCoreBundle\Features\Context\ContentContext::updateDraft PHP Method

updateDraft() public method

public updateDraft ( $fields )
    public function updateDraft($fields)
    {
        $contentService = $this->repository->getContentService();
        $updateStruct = $contentService->newContentUpdateStruct();
        foreach ($fields as $fieldDefIdentifier => $fieldValueUpdate) {
            $updateStruct->setField($fieldDefIdentifier, $fieldValueUpdate);
        }
        $updatedDraft = $this->repository->sudo(function () use($updateStruct) {
            return $this->repository->getContentService()->updateContent($this->currentDraft->versionInfo, $updateStruct);
        });
        return $this->currentDraft = $updatedDraft;
    }

Usage Example

 /**
  * This could belong in the content context.
  *
  * @Given /^I modify a field from the draft$/
  */
 public function iModifyAFieldFromTheDraft()
 {
     $this->contentContext->updateDraft(['name' => 'MODIFIED - ' . $this->contentContext->getCurrentDraft()->getFieldValue('name')->text]);
 }