Jump to content

PagesToJSON


evanmcd
 Share

Recommended Posts

Couple things I'm looking to do to improve this module are to:

  1. add the ability to pass in the native fields you'd like in the output
  2. add an option in the Field Details section for whether or not you want the field included in JSON output

Re the first one, I could use a bit of help trying to figure out how to pass options into a hooked function. I've tried adding an $options param to addHook, like this:

$this->addHook('PageArray::toJSON', $this, 'pagesToJSON', $options);

and calling it like this:

$myPages->toJSON(array('fields' => 'id,name'));

But, when I do I get this error:

Method PageArray::toJSON does not exist or is not callable in this context (in /Projects/TeamScheme/teamscheme_0.5/wire/core/Wire.php line 231)

If someone could point me in the right directions for adding params to hooked functions (and perhaps point to a module that implements something like I want to do wfor item #2) I would appreciate it.

Thanks.

Link to comment
Share on other sites

This sounds great Evan, I can't wait to check this one out. To answer your question about how to pass arguments to a hook function:

$myPages->toJSON($a, $b, $c); 

public function toJSON(HookEvent $event) {
 $a = $event->arguments[0];
 $b = $event->arguments[1];
 $c = $event->arguments[2]; 
}

Since you want to pass in an options array as the first argument, you would call your function like in your example, and you could retrieve the argument like this:

$options = $event->arguments[0]; 
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

×
×
  • Create New...