* - load arguments: (optional) An associative array of key/value pairs where
* parameter name is the key and a callback is the value. The callback will
* be passed a single argument, the value of the passed parameter. The JS
* module automatically detects any "PARAMETER_load" functions that exist
* based on if "process request" is enabled and the function explicitly
* specifies that parameter in it's callback function signature. For
* example: if one of the parameters passed is "node" and the callback
* function signature defines a $node argument, then a "node_load" function
* will be invoked (if the function exists). Optionally, to disable the
* automatic load callback for a parameter, you can set the callback to
* FALSE or to disable all automatic "load arguments" processing you may
* set FALSE for the entire "load arguments" property.
This a very, very powerful new feature. Suffice it to say, you no longer have to do things like the following in your callbacks:
function MODULE_js_callback_CALLBACK($nid) {
// $node is a fully loaded stdClass object.
$node => node_load($nid);
return $node->title;
}
Just change your existing $nid parameter to $node and the JS module will automatically load these entities for you:
function MODULE_js_callback_CALLBACK($node) {
// $node is a fully loaded stdClass object.
return $node->title;
}
The JS module will also validate any returned objects from the load function if there is a specific type hint in the function signature of the callback (this concept is almost verbatim of how D8 routes/callbacks work):
function MODULE_js_callback_CALLBACK(MyCustomObject $object) {
// $object is a fully loaded MyCustomObject object.
return $object->myCustomMethod();
}
While the introduction of this property my disrupt existing callbacks, at first, you can easily mitigate this change one of two ways:
- Update your callbacks to take advantage of this new feature (should be rather quick and easy to do).
- Nullify this new feature by setting the entire
load arguments"auto detection" capability toFALSE:
$callback['my_callback'] = array( 'load arguments' => FALSE, );Optionally, if you wish to keep a hybrid of this capability and keep backwards compatibility for existing parameters, you may disable this feature only on specific parameters:
$callback['my_callback'] = array( 'load arguments' => array( 'node' => FALSE, ), );