I have a website where TV repairmen enter tips and search for tips. Yesterday I upgraded CCK and Views to their most current versions. Since then, a Views created page I was using has an error. Node: Body lists the body and two other CCK fields.
Picture 1
If you look at picture 1 you can see the Node:body is labeled solution. Instead of just listing the last sentence, it lists model, man.year, and problem.
here is a picture of the fields for that content type.

I've been editing, deleting and re-creating this views page for the last 12 hours without success.
Thanks in advance for any help.

Comments

Rowanw’s picture

I believe CCK adds all extra fields into $body by design, and Views doesn't seem give you a way to extract $node->content['body']['#value'], which is normally what you'd use in a node template to get the body without the custom fields.

The simple (and time consuming) workaround would be to create a new field called "solution" and leave out the body all together, but there must be a way to modify the output with some PHP.

daniel sanchez’s picture

Thanks for the reply. That sounds like it makes sense. But it was working correctly before I upgraded.

daniel sanchez’s picture

If I add a new field (tip_solution) to this content type, is there a way to automatically migrate the info in body into this field? If I make it a text field, under default value, there is a php code field that I'm hoping can be used for this. However I'm a total php n00b. Any ideas.
Thank you.

inforeto’s picture

Try with the contemplate.module, it will show in views the body and teaser you want.

daniel sanchez’s picture

I decided that making the "solution" a new CCK text field would be the best solution in the long term. So I wrote a function to take the body of every node and put it into the newly created field. I saw that the database was updated but the new info would not show up on the website. I cleared the cache using Devel module and problem solved.
Thanks.

victorortiz’s picture

Ok, I decided to fix this problem because I need this working for a project. The problem is in hook_nodeapi of the content module. Here a function is defined that will be used to format the content of the node. When Views module call this function, before rendering the content, all the fields are added to the content of the node. Now this should depend on the handler of the field that is selected while configuring the View. What I did was to add a line of code that only allow the body to be added to the content if the handler is teaser. Now in the field section of your view you just need to set your handler for Node:Body field to Teaser.

Look in content.module for line 592, it should said:

<?php
$return[$field['field_name']] = array(
?>

Before that line add a condition like this:

<?php
if (!$teaser || ($teaser && $field['field_name'] == 'body')) {
?>

This is how it looks after its finished.

<?php
if (!$teaser || ($teaser && $field['field_name'] == 'body')) {
    $return[$field['field_name']] = array(
        '#weight' => $field['widget']['weight'],
        '#value' => $value,
        '#access' => $formatter != 'hidden',
    );
}
?>

If this does not work for you, please let me know.

xjm’s picture

For anyone that might stumble on this thread, check out http://drupal.org/node/160641 for a patch that resolves this issue.