You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pimcore技术问询:代码编辑已发布对象后如何保存新版本且不发布

Can I save edits to a published Pimcore object as a draft version while keeping the published version active?

Absolutely—this is fully supported in Pimcore, and it’s a core part of how the versioning and publishing workflow works. Here’s how to implement it in code, step by step:

Step 1: Load the published object

First, load your target object using the standard getById() method. By default, this will load the draft version if one exists; if not, it loads the live (published) version:

// Replace YourDataObjectClass with your actual Pimcore class name
$object = \Pimcore\Model\DataObject\YourDataObjectClass::getById($objectId);

// If you explicitly want to load the live version (ignoring any existing draft), use:
// $object = \Pimcore\Model\DataObject\YourDataObjectClass::getById($objectId, true);

Step 2: Modify the object

Make your desired changes to the object’s fields as you normally would:

$object->setTitle("Updated Title");
$object->setDescription("Revised description content");
// Add any other field modifications here

Step 3: Save as a draft (don’t publish!)

This is the critical part: call save() on the object, but do NOT call publish(). This will create a new version of the object in draft state, while leaving the existing published version fully active for the frontend:

$object->save();

What happens next?

  • The original published version remains the live version served to your frontend users.
  • Your edited changes are saved as a new draft version in Pimcore’s version history.
  • Editors can navigate to the object in the Pimcore UI, review the draft changes, and manually click the "Publish" button when they’re ready to make the draft the new live version.

Key Notes

  • Every save() call creates a new version entry in the object’s version history. You can view these versions in the UI under the "Versions" tab of the object.
  • To check if a version is published, you can use the isPublished() method on a version object:
    $versions = $object->getVersions();
    foreach ($versions as $version) {
        if ($version->isPublished()) {
            echo "This is the published version: " . $version->getVersionDate();
        }
    }
    
  • If you accidentally call publish() after saving, it will immediately replace the live version with your edits—so make sure to avoid that if you want to keep the original published version active for review.

This workflow aligns perfectly with the "edit, review, publish" process you’re looking for, and it doesn’t require any custom plugins or complex setup—just following these basic code practices.

内容的提问来源于stack exchange,提问作者L. Swarez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:51:02