View more context

 

wmk

Had fun time with umlauts in image urls uploaded to WP... the world can be so cruel

Mo

Friends don't let friends use WordPress...

🙏 (1) 👍 (2)
wmk

at least I found one more reason to migrate that content site to SS

Mo

On the rare occasion we take over a Wordpress site, we usually gentaly push the owner to convert to SS

Dave Toews

Is it possible to distinguish between Saving and Publishing within the validate() method on a DataObject?

nightjarnz

Not sure publishing makes that call. An object must be in a saved state in order to be published.

nightjarnz

I suppose you mean what used to be the "Save & publish" button - and I suppose my shot in the dark answer would be "no."

Dave Toews

Yup, that's what I mean, and yeah. Was hoping to be able to allow saving a draft even if fields were missing that are required for publishing.

Joe

oh! I just did something similar to this for a project

in getCMSFields(), I check to see if that object has all of the required fields. If one of them is missing that’s required for it to be published, then I remove the publish button.

in the validate method, I think I was able to check to see if the object is published already, and if it is, then I apply the stricter criteria.

💡 (1)
Dave Toews

You don't happen to recall how you removed the publish button? Is it part of the FieldList returned from parent::getCMSFields()?

Joe

hmm… i’ll have to look. give me a sec

Joe

oh! I overrode the canPublish() function, and just return false if any of my “required-to-publish” fields are empty

Joe

apparently I only half-remembered how I pulled this off lol

Dave Toews

Thanks again. That makes more sense, since I couldn't find the publish button.

Dave Toews

Got it working, but this method does have a loophole. If you've never published and save with the required fields then delete the content you have a publish button available unless you refresh the page.