On Page Save

I’m trying to write a plugin that posts to twitter when a new blog post is created. This is my thinking:

  • Listen for a save event
  • Check if data exists in the storage
  • Check taxonomy
  • Evaluate and act

The problem that I’m facing is that I’m not sure which event to use. I’m new to Grav, so I’m probably just missing something… I’ve looked at the Grav lifecylce to ascertain what event to use, but it seems to me that most of the events are aimed at “front-end” events (or events concerned with the delivery of the content, not so much the creation)

Could someone perhaps point me in the right direction?

There exists an onAdminSave event (see here https://github.com/getgrav/grav-plugin-admin/blob/8cd0279b018e40d1e3092fcc6821e8655e0c29f7/classes/controller.php#L1612). However, this is admin specific. Changes on the filesystem by uploading or deleting folders (i.e. via FTP, GitHub hooks etc.) are not taken into account. For this the only way I think is to use hooks like onPageProcessed and start from that.

Thanks Sommerregen. I was actually just starting to look at the Admin plugin, but this saves me some time.

For my use case, I’m happy with my plugin only being triggered by admin, but I guess if I was to make the plugin available to the community, I should consider the filesystem too?

Yes, as long as you only care about the Admin that’s totally enough. Considering the filesystem besides the admin use case is much appreciated, but should not be mandatory to publish your plugin. Even if your plugin only supports Admin for the moment, it will definitely an enrichment for the Grav community! :slight_smile:

Let’s see how it goes;) I’ll try for the most versatile.