You are here

function coder_upgrade_upgrade_call_filter_formats_alter in Coder 7.2

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

Implements hook_upgrade_call_filter_formats_alter().

File

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

Code

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

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

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

  // Process function call.
  $name =& $item->name;
  cdp('filter_formats');

  /*
   * If call has a parameter, then change it to $user and add global statement.
   * If no parameter, then this still implies current user in D6.
   * Set the existing assignment variable to itself at $index.
   * Ex: $formats = filter_formats($index);
   * becomes
   * global $user;
   * $formats = filter_formats($user);
   * $formats = $formats[$index];
   */
  $index = $item
    ->printParameter(0);
  cdp("index = '{$index}'");
  $p0 = $editor
    ->expressionToStatement('$user');
  $item
    ->setParameter(0, $p0);

  // Get the parent = statement (i.e. node) this function call is part of.
  $parent =& $item->parent;

  // Get the statement list the parent is part of.
  $container =& $parent->container;

  // Insert a statement.
  $statement = $editor
    ->textToStatements("global \$user;")
    ->getElement(0);
  $container
    ->insertBefore($parent, $statement, 'global');
  if ($index) {

    // Insert a statement.
    $assignment = $parent->data;
    $assign_variable = $assignment->values
      ->getElement()
      ->getElement()
      ->toString();
    cdp($parent->data
      ->print_r());
    $statement = $editor
      ->textToStatements("{$assign_variable} = {$assign_variable}\\[{$index}\\];")
      ->getElement(0);
    $container
      ->insertAfter($parent, $statement, 'assignment');
  }
}