titanium Posted November 11, 2016 Posted November 11, 2016 Hi, I would like to build a module which executes some functions when it's config dialog is saved. That's what I have so far: <?php class Patch extends WireData implements Module { public function init() { $this->addHookAfter('Modules::saveConfig', $this, 'runPatch'); } public function runPatch(HookEvent $event) { $this->message('runPatch has been executed'); } } This works so far, but it works for any module which is saved, which is not what I want - I just want to run the method "runPatch" when this particular module has been saved. How can I achieve that?
adrian Posted November 11, 2016 Posted November 11, 2016 It's all about checking the $event. Using Tracy, inside your runPatch() method, do this: bd($event); That will return something like: Now that shows that you are looking for: $event->arguments[0] Just to confirm, do: bd($event->arguments[0]); and you'll get: which shows that you can simply do: if($event->arguments[0] === 'MyModuleName') { 5
titanium Posted November 11, 2016 Author Posted November 11, 2016 Aaah, yes - I see clearly now. That works - many thanks for this Since I'm often to confused to remember that I have used the module's name more than just in the filename: is there a smart way to use the name of the module somewhat more dynamically, besides parsing the module's filename?
adrian Posted November 11, 2016 Posted November 11, 2016 3 minutes ago, titanium said: Since I'm often to confused to remember that I have used the module's name more than just in the filename: is there a smart way to use the name of the module somewhat more dynamically, besides parsing the module's filename? Sorry I am not understanding what you are asking here. In the example above we are not parsing the filename. Perhaps you can provide some code showing what you are currently doing.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now