Elgg  Version 2.2
Functions | Variables
hooks.js File Reference

Go to the source code of this file.

Functions

elgg provide ('elgg.config.hooks')
 
elgg register_instant_hook ('init', 'system')
 

Variables

elgg register_hook_handler
 Registers a hook handler with the event system. More...
 
elgg trigger_hook
 Emits a hook. More...
 
elgg register_instant_hook
 Registers a hook as an instant hook. More...
 
elgg is_instant_hook
 Is this hook registered as an instant hook? More...
 
elgg set_triggered_hook
 Records that a hook has been triggered. More...
 
elgg is_triggered_hook
 Has this hook been triggered yet? More...
 

Function Documentation

elgg provide ( 'elgg.config.hooks'  )
elgg register_instant_hook ( 'init ,
'system  
)

Variable Documentation

elgg is_instant_hook
Initial value:
= function(name, type) {
return elgg.is_in_object_array(elgg.config.instant_hooks, name, type);
}
elgg
Definition: install.js:23
list style type
Definition: admin.css.php:777
$site name

Is this hook registered as an instant hook?

Parameters
{String}name The hook name.
{String}type The hook type.

Definition at line 152 of file hooks.js.

elgg is_triggered_hook
Initial value:
= function(name, type) {
return elgg.is_in_object_array(elgg.config.triggered_hooks, name, type);
}
elgg
Definition: install.js:23
list style type
Definition: admin.css.php:777
$site name

Has this hook been triggered yet?

Parameters
{String}name The hook name.
{String}type The hook type.

Definition at line 172 of file hooks.js.

elgg register_hook_handler
Initial value:
= function(name, type, handler, priority) {
elgg.assertTypeOf('string', name);
elgg.assertTypeOf('string', type);
elgg.assertTypeOf('function', handler);
if (!name || !type) {
return false;
}
var hooks = elgg.config.hooks;
elgg.provide([name, type], hooks);
if (!(hooks[name][type] instanceof elgg.ElggPriorityList)) {
hooks[name][type] = new elgg.ElggPriorityList();
}
if (elgg.is_instant_hook(name, type) && elgg.is_triggered_hook(name, type)) {
handler(name, type, null, null);
}
return hooks[name][type].insert(handler, priority);
}
elgg
Definition: install.js:23
list style type
Definition: admin.css.php:777
$site name

Registers a hook handler with the event system.

For best results, depend on the elgg/ready module, so plugins will have been booted.

The special keyword "all" can be used for either the name or the type or both and means to call that handler for all of those hooks.

Note that handlers registering for instant hooks will be executed immediately if the instant hook has been previously triggered.

Parameters
{String}name Name of the plugin hook to register for
{String}type Type of the event to register for
{Function}handler Handle to call
{Number}priority Priority to call the event handler
Returns
{Boolean}

Definition at line 26 of file hooks.js.

elgg register_instant_hook
Initial value:
= function(name, type) {
elgg.assertTypeOf('string', name);
elgg.assertTypeOf('string', type);
return elgg.push_to_object_array(elgg.config.instant_hooks, name, type);
}
elgg
Definition: install.js:23
list style type
Definition: admin.css.php:777
$site name

Registers a hook as an instant hook.

After being trigger once, registration of a handler to an instant hook will cause the handle to be executed immediately.

Note
Instant hooks must be triggered without params or defaults. Any params or default passed will not be passed to handlers executed upon registration.
Parameters
{String}name The hook name.
{String}type The hook type.
Returns
{Number} integer

Definition at line 139 of file hooks.js.

elgg set_triggered_hook
Initial value:
= function(name, type) {
return elgg.push_to_object_array(elgg.config.triggered_hooks, name, type);
}
elgg
Definition: install.js:23
list style type
Definition: admin.css.php:777
$site name

Records that a hook has been triggered.

Parameters
{String}name The hook name.
{String}type The hook type.

Definition at line 162 of file hooks.js.

elgg trigger_hook

Emits a hook.

Loops through all registered hooks and calls the handler functions in order. Every handler function will always be called, regardless of the return value.

Warning
Handlers take the same 4 arguments in the same order as when calling this function. This is different from the PHP version!
Note
Instant hooks do not support params or values.

Hooks are called in this order: specifically registered (event_name and event_type match) all names, specific type specific name, all types all names, all types

Parameters
{String}name Name of the hook to emit
{String}type Type of the hook to emit
{Object}params Optional parameters to pass to the handlers
{Object}value Initial value of the return. Can be mangled by handlers
Returns
{Boolean}

Definition at line 75 of file hooks.js.