function coder_upgrade_callback_functions in Coder 7
Same name and namespace in other branches
- 7.2 coder_upgrade/conversions/other.inc \coder_upgrade_callback_functions()
Callback routine for function changes using grammar parser.
The grammar parser API which provides helper functions for working with function objects. Some examples of typical tasks follow.
// Rename the function.
$item->name = 'new_function_name';
// Update the document comment.
$item->comment = preg_replace('@hook_perm([^i])@', "hook_permission\$1", $item->comment);
// Get the list of body statements (note the use of the reference operator).
$body =& $item->body;
// Find the return statement in the function.
$return = $body
->find(T_RETURN, 'reverse');
For other examples of using the grammar parser API
Parameters
PGPNode $node: A node object containing a PGPClass (or function) item.
PGPReader $reader: The object containing the grammar statements of the file to convert.
See also
coder_upgrade_callback_function_calls
1 string reference to 'coder_upgrade_callback_functions'
- coder_upgrade_convert_functions in coder_upgrade/
conversions/ other.inc - Upgrades functions using grammar parser.
File
- coder_upgrade/
conversions/ other.inc, line 981 - Other conversion routine file for the coder_upgrade module.
Code
function coder_upgrade_callback_functions(&$node, &$reader) {
cdp("inside " . __FUNCTION__);
$item =& $node->data;
global $_coder_upgrade_module_name;
$name =& $item->name;
cdp("name = {$name}");
/*
* If the function name does not begin with the module name, then ignore it.
* This assumes such a function would be an instance of an API hook defined
* by the contributed module but implemented on behalf of another module. For
* this use case, the contributed module would define upgrade routines to
* allow other contributed modules that implement said API to upgrade their
* code.
*
* Example: the Views module defines hooks and implements them on behalf of
* core modules.
*
* Otherwise, strip the module name from the function name and use this as
* the key in the switch statement. In some cases (e.g. hook_update_N), some
* additional manipulation and testing needs to be done.
*/
if (strpos($name, $_coder_upgrade_module_name) !== 0) {
clp("Ignoring function '{$name}' as its name does not begin with the module name");
return;
}
// By convention, the module name should be followed by an underscore.
$key = substr($name, strlen($_coder_upgrade_module_name) + 1);
cdp("key = {$key}");
// Update hooks need additional manipulation.
if (preg_match('@update_\\d+$@', $key, $matches)) {
cdp(print_r($matches, 1));
$key = 'update_N';
}
switch ($key) {
case 'access':
// Changes: hook_node_access
coder_upgrade_convert_access($node);
break;
case 'block':
// Changes: remove_op
$callback = 'coder_upgrade_callback_block';
$op_index = 0;
coder_upgrade_convert_op($node, $callback, $op_index);
break;
case 'comment':
// Changes: remove_op
$callback = 'coder_upgrade_callback_comment';
$op_index = 1;
coder_upgrade_convert_op($node, $callback, $op_index);
break;
case 'install':
case 'uninstall':
// Changes: install-schema
coder_upgrade_convert_install($node);
break;
case 'menu_link_alter':
// Changes: hook_menu_link_alter
coder_upgrade_convert_menu_link_alter($node);
break;
case 'nodeapi':
// Changes: build_mode, remove_op and others !!!???
$callback = 'coder_upgrade_callback_nodeapi';
$op_index = 1;
coder_upgrade_convert_op($node, $callback, $op_index);
break;
case 'node_type':
// Changes: remove_op
$callback = 'coder_upgrade_callback_node_type';
$op_index = 0;
coder_upgrade_convert_op($node, $callback, $op_index);
break;
case 'perm':
// Changes: hook_permission and descriptions_permissions
coder_upgrade_convert_perm($node);
break;
case 'schema':
// Changes: schema_translation and schema_html
coder_upgrade_convert_schema($node);
break;
case 'update_N':
// Changes: update_php
coder_upgrade_convert_update_N($node);
break;
case 'user':
// Changes: remove_op, user_cancel and others !!!???
$callback = 'coder_upgrade_callback_user';
$op_index = 0;
coder_upgrade_convert_op($node, $callback, $op_index);
break;
}
}