Last active
October 8, 2015 01:26
-
-
Save somatonic/f386a76a5eb4adc2ae20 to your computer and use it in GitHub Desktop.
hook to track changes on save ready
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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