...
Code Block | ||||
---|---|---|---|---|
| ||||
try
{
// load the content info for the given id
$contentInfo = $contentService->loadContentInfo($contentId);
// create a draft from the current published version
$contentDraft = $contentService->createContentDraft($contentInfo);
// instanciate a content update struct
$contentUpdateStruct = $contentService->newContentUpdateStruct();
// set language for new version
$contentUpdateStruct->initialLanguageCode = 'eng-GB';
// set fields
$contentUpdateStruct->setField( 'title', $newtitle );
$contentUpdateStruct->setField( 'body', $newbody );
// update draft
$contentDraft = $contentService->updateContent($contentDraft->versionInfo, $contentUpdateStruct);
// publish draft
$content = $contentService->publishVersion($contentDraft->versionInfo);
print_r($content);
}
catch(\eZ\Publish\API\Repository\Exceptions\NotFoundException $e)
{
// react on content type not found
$output->writeln($e->getMessage());
}
catch(\eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException $e)
{
// react on a field is not valid
$output->writeln($e->getMessage());
}
catch(\eZ\Publish\API\Repository\Exceptions\ContentValidationException $e)
{
// react on a required field is missing or empty
$output->writeln($e->getMessage());
}
} |
...