Oliver Posted February 19, 2012 Posted February 19, 2012 I have a problem with assigning a process module to a process field as it has to happen on installation of the process module. As the code for assigning is executed as part of the ___install() method of the process module, the module - of course - isn’t actual installed yet and so it has no ID to be saved with the created page’s process field. The ID would be available after the installation has finished. But I haven’t found a way to actually call a second method to do the assigment. I thought about setting a hook on init after ModuleName::install, but as the hook would be set on every init of the module, it seemed not to be a very clever solution. Any other ideas?
apeisa Posted February 19, 2012 Posted February 19, 2012 Not sure if I understood correctly, but this is what I do at ShoppingOrdersManagement (which is a process module): public function install() { $orders = new Page(); $orders->template = $this->templates->get("admin"); $orders->parent = $this->pages->get($this->config->adminRootPageID); $orders->title = 'Manage orders'; $orders->name = 'manage-orders'; $orders->process = $this; $orders->save(); }
Oliver Posted February 20, 2012 Author Posted February 20, 2012 That’s right the way I tried. But there is no module ID saved in the database for the field. It sais 0. But yeah, as I installed your module successfully, it seems to work in your case. But where does it get the ID of the module from, as the module doesn’t have any the moment $orders->save(); is executed?
apeisa Posted February 20, 2012 Posted February 20, 2012 Good questions. I don't know Maybe install() saves the module first before executing any other code?
ryan Posted February 20, 2012 Posted February 20, 2012 Oliver, the module ID is already determined by the time your install() function is called. For instance, you could add this to your install function: $id = wire('modules')->getModuleID($this); However, when you do $page->process = $this; it is already doing the above for you behind the scenes.
pwFoo Posted June 25, 2018 Posted June 25, 2018 On 2/20/2012 at 8:41 PM, ryan said: Oliver, the module ID is already determined by the time your install() function is called. For instance, you could add this to your install function: $id = wire('modules')->getModuleID($this); However, when you do $page->process = $this; it is already doing the above for you behind the scenes. Good to know that "$page->process = $this" works to, but the process page could be configured by module info in later PW versions (topic is very old, I know...) Will a custom un-/install() method in process module overwrite the "default" methods (create page, set process field to module, ...) or will it extend the default process module un-/install? The page to create is set in module info as shown in the ProcessHello example // page that you want created to execute this module 'page' => array( 'name' => 'helloworld', 'parent' => 'setup', 'title' => 'Hello World' ), Anything to do if I try to extend / modify the default un-/install()? Should I hook after module install method and should that work? $this->addHookAfter('install', function (HookEvent $event) { // custom code }); And what do that line in example mean in example module install() / uninstall()? parent::___uninstall(); // always remember to call parent method Would be nice to know the default process module un-/install() methods or is it just a installPage() / uninstallPage() call?
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