You are here

function coder_upgrade_new_filter_hook in Coder 7.2

Same name and namespace in other branches
  1. 7 coder_upgrade/conversions/function.inc \coder_upgrade_new_filter_hook()
1 call to coder_upgrade_new_filter_hook()
coder_upgrade_convert_filter in coder_upgrade/conversions/function.inc
Updates hook_filter().

File

coder_upgrade/conversions/function.inc, line 831
Provides conversion routines applied to functions (or hooks).

Code

function coder_upgrade_new_filter_hook($node, $hook, $filters = array()) {

  // DONE
  global $_coder_upgrade_module_name;

  // Set values for the new hook function.
  $comment = array(
    'type' => T_DOC_COMMENT,
    'value' => "/**\n * Implements hook{$hook}().\n */",
  );
  $name = $_coder_upgrade_module_name . $hook;

  // '_filter_info';
  // Create the new hook function.
  $function = new PGPClass($name);
  $function->comment = $comment;
  $function->type = T_FUNCTION;
  $function->parameters = new PGPList();

  // Use the editor to set the function parameters.
  $editor = PGPEditor::getInstance();

  //  $editor->setParameters($function, $parameters);
  // Create body statements.
  $string = '';
  foreach ($filters as $key => $filter) {
    $string .= "\$filters[{$key}] = array(\n";
    foreach ($filter as $key2 => $value) {
      $string .= "  '{$key2}' => {$value},\n";
    }
    $string .= ");\n";
  }
  $string .= "return \$filters;\n";
  cdp(print_r($string, 1));

  // Copy the case (or if) block as the body of the function.
  $function->body = $editor
    ->textToStatements($string);
  cdp(get_class($function->body));
  cdp($editor
    ->statementsToText($function->body));
  if ($function->body
    ->isEmpty()) {
  }

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

  // Insert the new function before the old function.
  $container
    ->insertBefore($node, $function, 'function');

  // Insert a blank line.
  $whitespace = array(
    'type' => T_WHITESPACE,
    'value' => 1,
  );
  $container
    ->insertBefore($node, $whitespace, 'whitespace');
}