You are here

function coder_upgrade_callback_menu in Coder 7.2

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

Caches hook_menu() arrays.

Save a list of form callback routines (including arguments to drupal_get_form()).

Parameters

PGPNode $node: The node of the statement containing the array object.

PGPArray $array2: The array object containing the array element ($current2).

PGPNode $current2: The node object of the array element.

string $hook: The hook name.

string $type: The type (key or value) of the array element.

string $key: The key of the array element (or the most recent key).

string $value: The value of the array element (or NULL if element is a key).

File

coder_upgrade/conversions/begin.inc, line 185
Provides conversion routines applied to the directory before routines are applied to the files.

Code

function coder_upgrade_callback_menu($node, &$array2, &$current2, $hook, $type, $key, $value) {

  // NOT DONE
  global $_coder_upgrade_menu_registry;
  if (!$current2 instanceof PGPNode) {
    clp("ERROR: current2 is not a PGPNode object in hook_{$hook}");
    return;
  }

  //   $editor = PGPEditor::getInstance(); // @todo Not used.

  /*
   * With a nice array that includes all the menu items, we can check for a
   * page callback of 'drupal_get_form'. However, this is a default and could
   * be omitted. But because there could be 'funny' code such as inside the
   * foreach loop in our example function, we do not have an easy way to
   * determine if the menu item is a callback to be changed.
   *
   * Unlike other uses for this pattern, get in on the first call, do our
   * business, and then set the array pointer to the last item to avoid
   * redundant looping.
   */
  $callback = $array2
    ->findValue('page callback');
  $arguments = $array2
    ->findValue('page arguments');
  if ($callback && trim($callback
    ->toString(), "'\"") == 'drupal_get_form') {
    if ($arguments) {
      $operand = $arguments
        ->getElement();
      if ($arguments
        ->isType(T_ARRAY)) {
        $form = trim($operand
          ->getValue()
          ->toString(), "'\"");
        $_coder_upgrade_menu_registry[] = $form;
      }
      elseif ($arguments
        ->isType(T_CONSTANT_ENCAPSED_STRING)) {
        $form = trim($arguments
          ->toString(), "'\"");
        $_coder_upgrade_menu_registry[] = $form;
      }
    }
  }
  elseif ($callback) {

    // These callbacks are not affected by this change.
    //    $form = trim($callback->toString(), "'\"");
    //    $_coder_upgrade_menu_registry[] = $form;
  }
  elseif ($arguments) {

    // Depending on the code style, some of these will include callbacks.
    // But we can not be sure. Check for first parameter being $form_state.
    $operand = $arguments
      ->getElement();
    if ($arguments
      ->isType(T_ARRAY)) {
      $form = trim($operand
        ->getValue()
        ->toString(), "'\"");
      $_coder_upgrade_menu_registry[] = $form;
    }
    elseif ($arguments
      ->isType(T_CONSTANT_ENCAPSED_STRING)) {
      $form = trim($arguments
        ->toString(), "'\"");
      $_coder_upgrade_menu_registry[] = $form;
    }
  }

  // Set $current2 to last item in list to avoid redundant looping.
  $current2 = $array2->values
    ->last();
}