Jump to content

magic function name in PW Process module development


adrianmak
 Share

Recommended Posts

I'm really new on pw's module development. And I'm working on a process module.

I read a few of other core or 3rd party Process module, I found that there are some kind of similarity in method naming convention

Like,

public function executeXXXX () {

  // code

}

Take the ProcessField.module of pw core process module as an example

public function ___executeChangeType()

public function ___executeSaveChangeType()

public function ___executeImport()

public function ___executeExport()

However , I search thru the method name executeChangeType, executeSaveChangeType, executeImport executeExport

They are never been called in other function within the module

Link to comment
Share on other sites

These are automagically called by ProcessController when an URL segment is appended to the path of an admin page.

If an admin page url is http://server/processwire/adminpage/ and that page is called, the execute method is called.

But if you open, for example, http://server/processwire/adminpage/edit, the first letter of the URL segement (edit) is uppercased and it is appended to the process method, resulting in executeEdit.

Process methods with multiple uppercase letters (camel case) are called by passing URL segments with hyphens. The hyphens are stripped, but each letter after a hyphen is uppercased, so http://server/processwire/adminpage/point-me-to-crocodiles will look for a method executePointMeToCrocodiles in adminpage's process module.

This way, one doesn't have to set up another process module for a subtasks and create a page for it or parse even more form values in execute. For a new subtask XXX, it's sufficient to add links/form targets with an URL segment of xxx and define a matching executeXxx method.

A perfect starting point to learn more about creating process modules is the source code of Ryan's ProcessHello module, which can be found at github and in the module repository.

  • Like 9
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...