Skip to content

Instantly share code, notes, and snippets.

@somatonic
Last active October 8, 2015 01:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somatonic/f386a76a5eb4adc2ae20 to your computer and use it in GitHub Desktop.
Save somatonic/f386a76a5eb4adc2ae20 to your computer and use it in GitHub Desktop.
hook to track changes on save ready
<?php
/**
* Helper Module
* Example to track a change before page is saved
*
*/
class HelperHooks extends WireData implements Module {
/**
* getModuleInfo is a method required by all modules to tell ProcessWire about them
* @return array
*/
public static function getModuleInfo() {
return array(
'title' => 'Helper Hooks',
'version' => 100,
'summary' => '',
'href' => '',
'author' => 'Philipp Urlich',
'singular' => true,
'autoload' => true,
);
}
/**
* Initialize the module
*
* ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called
* when ProcessWire's API is ready. As a result, this is a good place to attach hooks.
*
*/
public function init() {
$this->addHookAfter('Pages::saveReady', $this, 'hookPagesSave');
}
public function hookPagesSave(HookEvent $event) {
// Modified page, already contains changes in memory, not yet in DB
$page = $event->arguments('page');
// If there is a change in your field
if ($page->isChanged('select_categories')) {
wire("log")->save("trackchanged", $page->select_categories);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment