You are here

function hook_upgrade_hook_alter in Coder 7

Same name and namespace in other branches
  1. 7.2 coder_upgrade/coder_upgrade.api.php \hook_upgrade_hook_alter()

Alters hook functions using the grammar parser.

This hook allows contributed modules to alter any function object using the grammar parser. The function block may be inside an interface or class, or a stand-alone statement block. For example:

function foo($bar) {

  // Stand-alone.
  if ($bar) {

    // Do something.
  }
}
class example {
  function foo($bar) {

    // Embedded.
    if ($bar) {

      // Do something.
    }
  }

}

Coder Upgrade will call this alter hook for each hook function in the file that was parsed. However, the function name must follow the naming convention for a hook, i.e, your_module_name_hook. If your module declares a hook for another module or otherwise digresses from the standard naming convention, then use hook_upgrade_file_alter() to alter this function.

Refer to the grammar parser documentation for details of the function object (i.e. PGPClass).

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.

$hook: The name of the function (excluding the module name).

See also

hook_upgrade_file_alter()

PGPClass

1 function implements hook_upgrade_hook_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

coder_upgrade_upgrade_hook_alter in coder_upgrade/conversions/function.inc
Implements hook_upgrade_hook_alter().
1 invocation of hook_upgrade_hook_alter()
coder_upgrade_convert_functions in coder_upgrade/includes/main.inc
Upgrades functions (or hooks) using grammar parser.

File

coder_upgrade/coder_upgrade.api.php, line 237
Documents hooks provided by this module.

Code

function hook_upgrade_hook_alter(&$node, &$reader, &$hook) {
  global $_coder_upgrade_module_name;

  // Get the function object.
  $item =& $node->data;

  // Modify hook function.
  switch ($hook) {
    case 'old_hook_name':

      // Rename the function.
      $item->name = $_coder_upgrade_module_name . '_new_hook_name';

      // Update the document comment.
      $item->comment['value'] = preg_replace('@\\* Implement\\s+@', "* Implements ", $item->comment['value']);
      if ($item
        ->parameterCount() > 1) {

        // Switch the first two parameters.
        $p0 = $item
          ->getParameter(0);
        $p1 = $item
          ->getParameter(1);
        $item
          ->setParameter(0, $p1);
        $item
          ->setParameter(1, $p0);
      }
      break;
    default:
      break;
  }
}