Pointing the Views handler for Node Body at another field handler-Collection of common programming errors

I want to be able to use a CCK field as my node body without affecting interoperability with Views generated by independent modules. Using hook_data_alter(), I have attempt to re-target the Views node body handler to look at the handler CCK has generated for my field, field_body. Unfortunately, I get some errors when I try to make use of my proposed solution.

/**
 * Implementation of hook_views_data_alter().
 */
function fieldbody_views_data_alter(&$data) {
  // When node_revisions table is added, join in content_field_body too.
  $data['node_revisions']['table']['join']['content_field_body'] = array(
    'left_field' => 'vid',
    'field' => 'vid',
  );

  // Use field_body handler info for node body.
  $data['node_revisions']['body'] =
    $data['node_data_field_body']['field_body_value'];

  // Really emphasize that we are using a different table.
  // Since this isn't doing anything, it may be redundant.
  $data['node_revisions']['body']['table'] = 'content_field_body';

  // A couple tweaks so it's a friendly Node Body replacement in the UI.
  $data['node_revisions']['body']['group'] = t('Node');
  $data['node_revisions']['body']['help'] =
    t('Full body text of the node.');
}

This code appears to work, but when I try to use the handler in practice, I get a warning:

user warning: Unknown column 'node_revisions.field_body_value' in 'field list' query: SELECT DISTINCT node.nid AS nid, node_revisions.field_body_value AS node_revisions_field_body_value, node_revisions.field_body_format AS node_revisions_field_body_format, node.type AS node_type, node.vid AS node_vid FROM node node LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid LIMIT 0, 10 in ../workspace/oa/profiles/openatrium/modules/contrib/views/includes/view.inc on line 771.

My interpretation of this is that the code is not pulling in the content_field_body table when the field is used, instead it just tries to use node_revisions.field_body_value.

Looking for any answers that resolve this problem or suggest a better strategy for my goal.

EDIT: Ugly Fallback Option

Use hook_views_default_views_alter() to scan every View for a defined body field, and swap it out for a standard CCK field. However, this will break all kinds of things, and not be very performance on cache clears.

  1. As the database field you are using is external to the node_revisions table, you should probably declare a relationship, in the same way done from Views for the uid field.

    // uid field
    $data['node_revisions']['uid'] = array(
      'title' => t('User'),
      'help' => t('Relate a node revision to the user who created the revision.'),
      'relationship' => array(
        'handler' => 'views_handler_relationship',
        'base' => 'users',
        'base field' => 'uid',
        'label' => t('user'),
      ),
    );
    

Originally posted 2013-11-09 23:17:07.