Global navigation

   Documentation Center
   eZ Studio & eZ Platform
     User Manual
     Technical Manual
   eZ Publish 4.x / legacy

eZ Publish (5.x)

eZ Publish 5.x | For eZ Platform & eZ Studio topics see Technical manual and User manual, for eZ Publish 4.x and Legacy topics see eZ Publish legacy

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


Code Block
titleupdate content
            // 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);
        catch(\eZ\Publish\API\Repository\Exceptions\NotFoundException $e)
            // react on content type not found
        catch(\eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException $e)
            // react on a field is not valid
        catch(\eZ\Publish\API\Repository\Exceptions\ContentValidationException $e)
            // react on a required field is missing or empty