You are here

function hook_upgrade_hook_HOOK_NAME_alter in Coder 7

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

Alters a hook function using the grammar parser.

This hook allows contributed modules to alter a 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.

See also

hook_upgrade_file_alter()

PGPClass

23 functions implement hook_upgrade_hook_HOOK_NAME_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_access_alter in coder_upgrade/conversions/function.inc
Implements hook_upgrade_hook_access_alter().
coder_upgrade_upgrade_hook_action_info_alter in coder_upgrade/conversions/function.inc
Implements hook_upgrade_hook_action_info_alter().
coder_upgrade_upgrade_hook_block_alter in coder_upgrade/conversions/function.inc
Implements hook_upgrade_hook_block_alter().
coder_upgrade_upgrade_hook_comment_alter in coder_upgrade/conversions/function.inc
Implements hook_upgrade_hook_comment_alter().
coder_upgrade_upgrade_hook_elements_alter in coder_upgrade/conversions/function.inc
Implements hook_upgrade_hook_elements_alter().

... See full list

File

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

Code

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

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

  // 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);
  }
}