Detect if a draft for a new entry is being created in save hook #10370
-
I'm trying to write a hook that sets a default value for a newly created entry. Surprisingly, detecting if an element is completely new, not saved and published yet is surprisingly difficult. I'm looking at this SE post by @brandonkelly for reference. Looks like Based on the other properties, the closest I can get is As a broader note, would be great to have this information in the event code generator in the docs. Right now there's only an Element is new checkbox, but it's ambiguous what 'new' means in this context. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I’m not sure what you’re looking for actually exists… Craft doesn’t let you create a new entry and a new draft for it at the exact same time. Entries will always start in one of these states:
In neither case will an additional draft be created right off the bat, though. |
Beta Was this translation helpful? Give feedback.
I’m not sure what you’re looking for actually exists… Craft doesn’t let you create a new entry and a new draft for it at the exact same time. Entries will always start in one of these states:
$event->isNew && $event->sender->firstSave
).$event->isNew && $event->sender->getIsUnpublishedDraft()
).In neither case will an additional draft be created right off the bat, though.