You are here

function coder_upgrade_upgrade_call_node_invoke_nodeapi_alter in Coder 7.2

Same name and namespace in other branches
  1. 7 coder_upgrade/conversions/call.inc \coder_upgrade_upgrade_call_node_invoke_nodeapi_alter()

Implements hook_upgrade_call_node_invoke_nodeapi_alter().

File

coder_upgrade/conversions/call.inc, line 2043
Provides conversion routines applied to function calls.

Code

function coder_upgrade_upgrade_call_node_invoke_nodeapi_alter(&$node, &$reader) {

  // DONE
  // Create helper objects.
  $editor = PGPEditor::getInstance();

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

  // Process function call.
  $name =& $item->name;
  $name['value'] = 'module_invoke_all';
  if ($item
    ->parameterCount() < 2) {
    $item
      ->insertStatementBefore($editor
      ->commentToStatement('// TODO The $hook parameter should not be null. Please declare and initialize a $hook parameter.'));
    $editor
      ->insertParameter($item, 0, 'node_ . $hook /* TODO Set this variable. */');
    return;
  }
  $op = $item
    ->getParameter(1);
  $p2 = $item
    ->printParameter(2);
  $p3 = $item
    ->printParameter(3);
  $item
    ->deleteParameter(3);
  $item
    ->deleteParameter(2);
  $item
    ->deleteParameter(1);
  if ($op
    ->isType(T_CONSTANT_ENCAPSED_STRING)) {
    $operation = trim($op
      ->toString(), "'\"");
    switch ($operation) {
      case 'delete':
      case 'insert':
      case 'load':
      case 'prepare':
      case 'presave':
      case 'update':
      case 'validate':

        // This operation hook becomes node_x
        break;
      case 'prepare translation':
      case 'search result':
      case 'update index':

        // This operation hook becomes node_x_x
        $operation = str_replace(" ", "_", $operation);
        break;
      case 'alter':

        // This operation hook becomes node_build_alter
        $operation = 'build_alter';
        break;
      case 'delete revision':

        // This operation hook becomes node_revision_delete
        $operation = 'revision_delete';
        break;
      case 'print':

        // This operation hook becomes node_view with $view_mode = 'print'
        $operation = 'view';
        $p2 = "'print'";
        break;
      case 'rss item':

        // This operation hook becomes node_view with $view_mode = 'rss'
        $operation = 'view';
        $p2 = "'rss'";
        break;
      case 'view':

        // This operation hook becomes node_view with $view_mode = 'full' by default
        if ($p2 && !in_array(strtolower($p2), array(
          'null',
          'false',
        ))) {
          $p2 = "'teaser'";
        }
        elseif ($p3 && !in_array(strtolower($p3), array(
          'null',
          'false',
        ))) {
          $p2 = "'full'";
        }
        break;
      default:
        cdp("ERROR: Invalid case value");
        return;
    }
    $p0 = "'node_" . $operation . "'";
  }
  else {
    $p0 = "'node_' . " . $op
      ->toString();

    // Let's assume $p2 is valid.
    //    $p2 .= $p2 ? " /* TODO: Set this parameter based on the " . $op->toString() . " hook */" : '';
  }
  $editor
    ->insertParameter($item, 0, $p0);
  if ($p2) {
    $editor
      ->setParameter($item, 2, $p2);
  }
}