Jump to content

Captain Hook - ProcessWire Hooks Cheatsheet


Soma

Recommended Posts

Captain Hook

ProcessWire Hooks Cheatsheet

http://somatonic.github.com/Captain-Hook/

or on processwire.com

http://processwire.com/api/hooks/

I created a simple list with a live search for all hookable methods available in the core.

All methods prefixed with a "___" (3 underscores) are hookable. Methods can be made hookable by simply adding those ___ to it.

-------------------------

I usually don't really need this, but thought it would be good to have an official list for reference. I used Sublime Text2 for searching and dumb a file with a search for " ___" in wire core. From this list I created a html file with a php script and added some fuzzy live search, similar to the API cheatsheet.
 

If you use Sublime Text 2 like me you can simple use Goto Anything command super+p to show a fuzzy search for files. Enter a class name you want to search for. For example "fields" or "process page edit" you will recieve a list of files found in PW. Highlight the file and typ a @ to see the symbol list quickly or select the file and super+r the get the symbol list.

  • Like 21
  • Thanks 2
Link to comment
Share on other sites

I love the name Soma. :) Great idea. Seems like we should link or mirror this like we're doing with the cheatsheet. Since I regularly add new hooks, how is it best kept up-to-date?

Link to comment
Share on other sites

Thanks Ryan. The name was in my head since a long time. All these hooking...

It's easy, it takes me 5 minutes to update. Download new repo, file search in sublime, copy result file over, hit refresh, upload new index.html.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 6 months later...

I just updated the sheet to 0.3 with hooks from latest dev version. 

+ 22 hooks registered.

- added teppo's article to info section links (http://www.flamingruby.com/blog/using-hooks-to-alter-default-behavior-of-processwire/)

- added link to ryan's tutorial using hook to add method to PageArray (http://processwire.com/talk/topic/4834-simple-hooks-tutorial-turn-a-pagearray-into-a-list-of-links/)

  • Like 8
Link to comment
Share on other sites

  • 6 months later...

The current Captain Hook's line numbers are not in sync with the dev branch. Perhaps there should be a stable Captain Hook which points to the master branch and a version for the dev branch, which suggests that line numbers could be out of sync because of Ryan adding stuff in the core, obviously.

An example I just saw:

#843: public function ___saveModuleConfigData($className, array $configData) {

I'm sure there are more.

OR: Ryan runs the generator before every commit =)

There is a generator, right?

Link to comment
Share on other sites

Thanks for mention it owzim, coincidently I just looked at that the day before you, and also seen that some lines are out of sync.

I was thinking if there's a way to automate it or make it easier to update. Currently I just do it manually scanning with SublimeText and take the result list to convert it to html. I'm just not sure what the easiest or best method could be.

If anyone got a good idea or knows how, please share.

Two versions, one for stable and one latest dev would be cool. 

For myself I'm not really using it the sheet, as I use SublimeText to quick find classes and symbols to quickly get an overview of the ___ methods. So a matter of a few seconds to look them up. 

Link to comment
Share on other sites

I just patched together some simple PHP code to scan for hooks:

https://gist.github.com/owzim/6f7c2ef6394f25e04269

I think we could go from there and build a shell script that

  • clones/pulls the PW repo
  • checks out master and generates html > captain-hook-master.html
  • checks out dev and generates html > captain-hook-dev.html
  • updates the github page

What do you think?

  • Like 2
Link to comment
Share on other sites

  • 4 months later...

tried to hook, but didn't work, then I realized only two undescores. Shouldn't this to be hookable, since $event object is only used in hooks? Is there an underscore missing?
wire/core/HookEvent.php

/**
* Return a string representing the HookEvent
*
*/
public function __toString() {
$s = $this->object->className() . '::' . $this->method . '(';
foreach($this->arguments as $a) $s .= is_string($a) ? '"' . $a . '", ' : "$a, ";
$s = rtrim($s, ", ") . ")";
return $s;
}

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
  • Recently Browsing   0 members

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