0

Is there a way to detect if a entry is being saved as a draft vs being published so when onAfterElementSave is called, so I don't save data to the database when it is a draft.

1

Actually, onAfterElementSave doesn't get called at all when saving a draft, so there's nothing to worry about.

When you load a draft in the CP, your field type will be passed in a $value based on the POST data for the field back when the draft was last saved (which is the same thing that happens when saving an entry fails due to validation errors).

2
  • For some reason that method is being called in my plugin when I save the entry as a draft. I am using "Craft Pro 2.2.2596".
    – aran
    Oct 23 '14 at 16:25
  • 1
    @aran Is that for a brand new entry? In that case it will get called, but it won't matter because the entry will be disabled and there's no chance you'll be overwriting existing data for the entry. Oct 24 '14 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.