function coder_upgrade_convert_filter_tips in Coder 7.2
Same name and namespace in other branches
- 7 coder_upgrade/conversions/function.inc \coder_upgrade_convert_filter_tips()
Updates hook_filter_tips().
hook_filter() and hook_filter_tips() replaced by hook_filter_info().
@todo This should fit into the convert_op use case.
Parameters
PGPNode $node: A node object containing a PGPClass (or function) item.
Return value
array Array of tip callback functions indexed by $delta.
1 call to coder_upgrade_convert_filter_tips()
- coder_upgrade_convert_filter in coder_upgrade/
conversions/ function.inc - Updates hook_filter().
File
- coder_upgrade/
conversions/ function.inc, line 897 - Provides conversion routines applied to functions (or hooks).
Code
function coder_upgrade_convert_filter_tips(&$node) {
// DONE
cdp("inside " . __FUNCTION__);
$item =& $node->data;
global $_coder_upgrade_module_name;
// Rename function.
$item->name .= '_XXX';
// Update document comment.
// $item->comment .= 'This function is obsolete.'; // TODO Make a comment manipulation routine.
// Restructure the triggers array.
$body =& $item->body;
if (!($switch1 = $body
->find(T_SWITCH))) {
clp("ERROR: switch statement not found in hook_filter_tips");
return array();
}
/*
* Compare first parameter to first switch condition (s/b $op)
*
* Read $delta case block: case operand gives the key for array
* Return value gives the array value for above keys
* Build array internally, then write it out.
*
* Look for a hook_filter_tips($delta, $format, $long = false).
* If present:
* - if multiple $delta bodies, then create new callback functions using
* $delta as part of the function name
* - else if one, then create new callback function
* - remove the $delta parameter
* - add tips_callback parameters to filter_info array items
*
* - TODO Case 2: could be an if block
*/
$operand1 = $switch1->conditions
->toString();
if ($operand1 != $item
->printParameter()) {
clp("ERROR: switch statement operand does not match first function parameter in hook_filter_tips");
return array();
}
// Remove first parameter for new callback function.
// TODO Do we need to clone this object for each new function???
$parameters1 = $item->parameters;
$parameters1
->deleteElement();
$tips = array();
// Get list of case statements.
$cases1 = $switch1->body;
$current1 = $cases1
->first();
while ($current1->next != NULL) {
$case1 = $current1->data;
if (!$case1 instanceof PGPCase || $case1->type == T_DEFAULT) {
$current1 = $current1->next;
continue;
}
// Get the $delta value.
$key1 = trim($case1->case
->toString(), "'\"");
cdp("key1 = {$key1}");
$body1 = $case1->body
->getElement();
// Make a new callback function.
$hook = '_filter_tips_' . $key1;
coder_upgrade_new_filter_tips_hook($node, $hook, $parameters1, $body1);
// Store callback name in return array.
$tips[$key1] = $_coder_upgrade_module_name . $hook;
$current1 = $current1->next;
}
// Delete the function body.
$item->body
->clear();
return $tips;
}