function coder_upgrade_callback_action_info in Coder 7.2
Same name and namespace in other branches
- 7 coder_upgrade/conversions/function.inc \coder_upgrade_callback_action_info()
Updates hook_action_info() arrays.
The arrays returned by hook_action_info(), hook_action_info_alter(), actions_list(), actions_get_all_actions(), actions_actions_map() were changed.
@todo The other functions listed above. @todo Database table {actions} - 'description' field is now called 'label'.
Parameters
PGPNode $node: The node of the statement containing the array object.
PGPArray $array2: The array object containing the array element ($current2).
PGPNode $current2: The node object of the array element.
string $hook: The hook name.
string $type: The type (key or value) of the array element.
string $key: The key of the array element (or the most recent key).
string $value: The value of the array element (or NULL if element is a key).
File
- coder_upgrade/
conversions/ function.inc, line 1712 - Provides conversion routines applied to functions (or hooks).
Code
function coder_upgrade_callback_action_info($node, &$array2, &$current2, $hook, $type, $key, $value) {
// DONE (NEEDS WORK on other functions listed above)
cdp("inside " . __FUNCTION__);
if (!$current2 instanceof PGPNode) {
clp("ERROR: current2 is not a PGPNode object in hook_{$hook}");
return;
}
$editor = PGPEditor::getInstance();
// The keys of this array are the action function items.
if ($type == 'key' && $key == 'description') {
cdp("Found the description key");
if (!$current2->data
->isType(T_CONSTANT_ENCAPSED_STRING)) {
clp("ERROR: key expression is not a string in hook_{$hook}");
return;
}
// Change key from 'description' to 'label.'
$current2->data = $editor
->expressionToStatement("'label'");
}
elseif ($type == 'key' && $key == 'hooks') {
cdp("Found the hooks key");
if (!$current2->data
->isType(T_CONSTANT_ENCAPSED_STRING)) {
clp("ERROR: key expression is not a string in hook_{$hook}");
return;
}
// Change key from 'hooks' to 'triggers.'
$current2->data = $editor
->expressionToStatement("'triggers'");
// Find the value element for this key.
if (!$array2
->findNextValue($current2)) {
clp("ERROR: did not find a value expression for the triggers key in hook_{$hook}");
return;
}
if (!$current2->data
->isType(T_ARRAY)) {
clp("ERROR: value expression is not a PGPArray object in hook_{$hook}");
return;
}
/*
* The triggers (formerly hooks) element is an associative array keyed by
* module name with its value being an array of actions. The new format
* combines the module name and action, eliminating one nested array.
* Example:
* 'hooks' => array(
* 'comment' => array('insert', 'update'),
* "taxonomy" => array("insert", "update", "delete", "view"),
* )
*
* 'triggers' => array(
* 'comment_insert', 'comment_update',
* 'taxonomy_insert', 'taxonomy_update', 'taxonomy_delete', 'taxonomy_view'
* )
*/
$triggers =& $current2->data
->getElement();
$ops = array();
$trigger = $triggers->values
->first();
while ($trigger->next != NULL) {
if ($trigger->type == 'key') {
// This is the module (or content type) the action pertains to.
$prefix = trim($trigger->data
->toString(), "'\"");
}
elseif ($trigger->type == 'value') {
if (!$trigger->data
->isType(T_ARRAY)) {
clp("ERROR: trigger value expression is not a PGPArray object in hook_{$hook}");
return;
}
// This is the array of action operation items.
$operation_items = $trigger->data
->getElement();
$string = $operation_items->values
->toString();
$items = explode(', ', $string);
foreach ($items as $op) {
$ops[] = "'{$prefix}_" . trim($op, "'\"") . "'";
}
}
$trigger =& $trigger->next;
}
$string = 'array(' . implode(', ', $ops) . ')';
$editor = PGPEditor::getInstance();
$expression = $editor
->expressionToStatement($string);
// TODO Use multiline format? Depending on number of items?
$expression
->getElement()->multiline = 1;
$expression
->getElement()->preserve = 0;
// Replace the triggers nested array with new array.
$triggers = $expression;
}
}