Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.