I am currently trying to write a plugin that will post to Facebook and Twitter when a new news item has been published.
I have the plugin code working, my main problem is getting the plugin to run. I have OnDocPublished checked for the plugin.
It runs fine if I create the page and save it unpublished, and then right click on the page in the resource tree and select publish there.
But if I create the page click the published box and save it, it doesn’t seem to fire the plugin.
Any help appreciated, is there a diff system event that i am missing for doing this.
Using MODx Revolution 2.0.0-rc-1 rev6254
-
☆ A M B ☆
- 427 Posts
-
MODX Staff
- 10,725 Posts
All you need do is have the plugin listen on both OnDocPublished and OnDocFormSave to handle cases where someone is directly calling the publishing action, with it’s own event vs. editing a document and changing the published status (potentially along with a great many other things).
I do not agree that this is a bug; it may not be totally intuitive to have to handle both events, but this is the way the event model is currently implemented and used.
ok so if I set both will the plugin only be called if the publish state has changed or will I need to do some checks within the code to see if the published has changed from unpublished to published.
Take a look at the ActivationEmail plugin. It sends an email when the user’s status changes from inactive to active. You want to do the same thing when a resource changes from unpublished to published.
You should be able to copy it and modify it to do what you want (changing the events, changing $user to $resource, and changing the field it looks at and performing your action instead of sending the email).
Thank you for the reply! I’ve checked the plugin but I’m afraid I still don’t understand what to do.
What I have in mind is a plugin which makes a new topic on phpBB forum once manager on my site creates a new document (and my MODx is configured to publish all new documents by default). The plugin must take the ID of the new document to generate a link. I figured how to check if the state of the document has changed (so, the case when the document already exists and the manager publishes it), but it’s still vague for me what event I should connect my plugin to, in order to be able to retrieve the ID of a newly created document.
Could you please explain a bit further?