Jump to content

Best practices for a module auto-saving field values


gRegor
 Share

Recommended Posts

I am working on a plugin to implement webmentions in ProcessWire. Webmention is a modern update to Pingback - a simple way to notify a URL that you linked to it, without the XMLRPC overhead.

I'm working on a module and an accompanying Fieldtype to store the webmention data. I'm using the Comments module as starting point and mostly understanding it. The thing I'm not sure about, though, is the best way to have the module automatically save the values for webmentions when they are sent (or received).

Similar to the Comments module, I have a WebmentionArray class and WebmentionItem class. In the module, I'm hooking Pages::saved to send webmentions and log them. Should I do something like:

// inside the Pages::saved hook

$page = $event->arguments('page');

$webmention = new WebmentionItem();

// set webmention fields (these keys exist in the Fieldtype)
$webmention->set('source_url', 'http://example.com/source');
$webmention->set('target_url', 'http://example.com/target');

// add webmention to field array
$page->webmentions->add($webmention);

$page->save();

Do I need to deal with a WebmentionArray class at all in this scenario, or does $page->webmentions->add() automatically handle adding it to the array?

Link to comment
Share on other sites

  • 3 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...