Quote from: peteedley at Feb 07, 2010, 03:21 PM
I know from previous posts and questions that onDocPublished is not fired if the doc is published at save.
Right, but OnDocFormBeforeSave/OnDocFormSave is.
Quote from: peteedley at Feb 07, 2010, 03:21 PM
I assume and my investigations show that there is no way to check if the published check box has changed during edit or creation. Is this correct?
Bad assumption; OnBeforeDocFormSave you can check the $_POST and compare to the value on the $resource. This event is fired before the POSTed data is written to the object.
Quote from: peteedley at Feb 07, 2010, 03:21 PM
So with this in mind this is what I am considering but I am open to better ways to deal with this.
1) Write a plugin that fires on onDocFormRender that checks the state of the published field.
(Not 100% sure how to but can figure it out)
2) Store this information some where.
Session Variable, Cookie? Any suggestions to best place
3) Now fire plugin to publish to twitter on onDocFormSave check for published field state compare to initial state and if changed from unpublished to publish then post
4) The same snippet would also have to fire on onDocPublish to cover that too so would need to check on which trigger fired it within plugin too.
I know that I could add a TV but since these are on a seperate page to the content edit box I don’t want the guys posting the pages to have to remeber to switch tabs change the tv to publish and then save. i want to run it all automatcally so pages under a certain container are allways posted to twitter once published.
All you need do is register both OnDocFormBeforeSave (where you will check the values) and OnDocFormSave/OnDocPublished (where you will make the Twitter API call). Since the OnDocForm events are in the same request, you could use just about any method to track that, including but not limited to, REQUEST variables, SESSION variables, MODx placeholders, MODx registry entries (which could be permanent so you could keep from Tweet’ing about the same Resource more than once if it was unpublished and republished again in the future), or some other method of your creation, etc.