You are here

function coder_upgrade_callback_block in Coder 7

Same name in this branch
  1. 7 coder_upgrade/conversions/other.inc \coder_upgrade_callback_block()
  2. 7 coder_upgrade/conversions/function.inc \coder_upgrade_callback_block()
Same name and namespace in other branches
  1. 7.2 coder_upgrade/conversions/other.inc \coder_upgrade_callback_block()
  2. 7.2 coder_upgrade/conversions/function.inc \coder_upgrade_callback_block()

Updates hook_block().

hook_nodeapi, hook_node_type, hook_user, and hook_block removed and replaced with families of related functions

2 string references to 'coder_upgrade_callback_block'
coder_upgrade_callback_functions in coder_upgrade/conversions/other.inc
Callback routine for function changes using grammar parser.
coder_upgrade_upgrade_hook_block_alter in coder_upgrade/conversions/function.inc
Implements hook_upgrade_hook_block_alter().

File

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

Code

function coder_upgrade_callback_block($node, $case_node, $operation = '') {
  cdp("inside " . __FUNCTION__);
  if (!$operation) {
    $case =& $case_node->data;
    if (!$case instanceof PGPCase || $case->type == T_DEFAULT) {
      cdp("Houston, we've got an unexpected statement");
      return;
    }
    $operation = $case->case
      ->toString();
    $operation = trim($operation, "'\"");
  }
  $hook = '_block_' . str_replace(' ', '_', $operation);
  $parameters = array(
    '$delta',
  );
  switch ($operation) {
    case 'configure':

      // This block becomes example_block_configure
      break;
    case 'list':

      // This block becomes example_block_list
      $hook = '_block_info';
      $parameters = array();
      break;
    case 'save':

      // This block becomes example_block_save
      $parameters = array(
        '$delta',
        '$edit',
      );
      break;
    case 'view':

      // This block becomes example_block_view
      break;
    default:
      cdp("ERROR: Invalid case value");
      return;
  }

  // http://drupal.org/node/224333#block_deltas_renamed
  // Change numeric block keys to strings
  $editor = PGPEditor::getInstance();
  $body =& $case_node->data->body;
  $text = $body
    ->toString();
  $search = array(
    '/\\$blocks\\[(\\d+)\\]/si',
    '/\\$delta ?([=!])= ?(\\d+)/si',
    '/case (\'|"|)(\\d+)(\'|"|)/si',
  );
  $replace = array(
    '$blocks[\'delta-\\1\']',
    '$delta \\1= \'delta-\\2\'',
    'case \'delta-\\2\'',
  );
  $count = 0;
  $text = preg_replace($search, $replace, $text, -1, $count);
  if ($count) {
    $body = $editor
      ->textToStatements($text);
    $body
      ->insertFirst($editor
      ->commentToStatement('// TODO Rename block deltas (e.g. delta-0) to readable strings.'), 'comment');
  }

  // Create the new hook function.
  coder_upgrade_op_to_hook($node, $case_node, $hook, $parameters);
}