Jump to content


Photo

Assigning a module to process field on installation


  • Please log in to reply
4 replies to this topic

#1 Oliver

Oliver

    Sr. Member

  • Members
  • PipPipPipPip
  • 134 posts
  • 27

  • LocationBasel, Switzerland

Posted 19 February 2012 - 05:03 PM

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?

#2 apeisa

apeisa

    Hero Member

  • Moderators
  • 3,160 posts
  • 1711

  • LocationVihti, Finland

Posted 19 February 2012 - 05:07 PM

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();
}


#3 Oliver

Oliver

    Sr. Member

  • Members
  • PipPipPipPip
  • 134 posts
  • 27

  • LocationBasel, Switzerland

Posted 20 February 2012 - 06:43 AM

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?

#4 apeisa

apeisa

    Hero Member

  • Moderators
  • 3,160 posts
  • 1711

  • LocationVihti, Finland

Posted 20 February 2012 - 06:56 AM

Good questions. I don't know :) Maybe install() saves the module first before executing any other code?

#5 ryan

ryan

    Reiska

  • Administrators
  • 7,810 posts
  • 6603

  • LocationAtlanta, GA

Posted 20 February 2012 - 02:41 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users