You are here

function coder_upgrade_callback_theme in Coder 7.2

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

Updates hook_theme() arrays.

Each theme function must register how it integrates with drupal_render().

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/function.inc, line 2087
Provides conversion routines applied to functions (or hooks).

Code

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

  // DONE
  cdp("inside " . __FUNCTION__);
  if (!$current2 instanceof PGPNode) {
    clp("ERROR: current2 is not a PGPNode object in hook_{$hook}");
    return;
  }
  $editor = PGPEditor::getInstance();

  // The keys of this array are the theme items.
  if ($type == 'key' && $key == 'arguments') {
    cdp("Found the arguments key");
    if (!$current2->data
      ->isType(T_CONSTANT_ENCAPSED_STRING)) {
      clp("ERROR: key expression is not a string in hook_{$hook}");
      return;
    }

    // Save the key expression for possible modification.
    $key_expression =& $current2->data;

    // Find the value element for this key.
    if (!$array2
      ->findNextValue($current2)) {
      clp("ERROR: did not find a value expression for the arguments key in hook_{$hook}");
      return;
    }
    if (!$current2->data
      ->isType(T_ARRAY)) {
      clp("ERROR: value expression is not a PGPArray object in hook_{$hook}");
      return;
    }
    $array = $current2->data
      ->getElement();
    if (!($key0 = $array
      ->getKey())) {

      // Change key from 'arguments' to 'variables.'
      $key_expression = $editor
        ->expressionToStatement("'variables'");
      return;
    }
    $key0 = trim($array
      ->getKey()
      ->toString(), "'\"");

    // At a minimum, an array with key-value pairs will have 4 keys after one
    // pair: lparens, key, assign, and value.
    // What other likely values are there for a render element?
    // Does $form ever appear with other variables? If so, how is this to be handled?
    // TODO This is not a deterministic way of setting the key.
    if ($array->count == 1 && in_array($key0, array(
      'form',
      'element',
      'elements',
    ))) {

      // if ($array->values->count() == 4 && in_array($key0, array('form', 'element'))) {
      // Change key from 'arguments' to 'render element.'
      $key_expression = $editor
        ->expressionToStatement("'render element'");

      // Change value from an associative array to a string.
      $current2->data = $editor
        ->expressionToStatement("'{$key0}'");
    }
    else {

      // Change key from 'arguments' to 'variables.'
      $key_expression = $editor
        ->expressionToStatement("'variables'");
    }
  }
}