I have a filed called field_output_PDF (a CCK FileField file upload filed)

I have another filed called filed_output_size (a computed filed)

In setting:

Computed Code:

function byte_convert($bytes)
  {
    $symbol = array('Bytes', 'KB', 'MB');

    $exp = 0;
    $converted_value = 0;
    if( $bytes > 0 )
    {
      $exp = floor( log($bytes)/log(1024) );
      $converted_value = ( $bytes/pow(1024,floor($exp)) );
    }

    return sprintf( '%.2f '.$symbol[$exp], $converted_value );
  }

$node_field[0]['value'] = byte_convert($node->field_output_pdf[0]['filesize']);

"Display this field" is checked

"Display Format" is
$display = $node_field_item['value'];

If "Store using the database settings below" is checked, I can choose this field (filed_output_size) from View UI setting. However, its value is EMPTY. And if I go to /node/123, I cannot see field_output_size at all.

However, if I do not check "Store using the database settings below", then the size value cannot be viewed from /node/123. But I am unable to choose this field from View UI setting. On view page, it gives this error:

Broken handler node_data_field_output_size.field_output_size_value

Comments

bigheadfish’s picture

A typo:

However, if I do not check "Store using the database settings below", then the size value cannot be viewed from /node/123. But I am unable to choose this field from View UI setting. On view page, it gives this error:

should be

However, if I do not check "Store using the database settings below", then the size value CAN be viewed from /node/123. But I am unable to choose this field from View UI setting. On view page, it gives this error:

bigheadfish’s picture

It is my fault.

Please close it.

Thanks.

akabret’s picture

Yikes! I don't know what bigheadfish did, but I have this *exact* problem and I don't know what I'm doing wrong!

I need to show a computed field in a view, but can't without having it first stored in the database ...which has its own problems.

Any help would be greatly appreciated!

Moonshine’s picture

Category: bug » support

Well, at best, non-db stored computed fields would have *very* limited functionality in Views if they were added. They couldn't be used as filters, for relationships, for sorting, etc. AFAIK they could only (potentially) be used as simple "display" fields.

However, even that would be a can of worms for most users, as the php code people often use depends on having a full $node object around to use, which may not be available depending on what is chosen for View output options. (only Node row output in views loads the full node objects as far as I know)

In any event, if you are just looking to cook up some dynamic output as part of a View you can always use a custom preprocess function to create extra variables that would get sent into the template for the view. Technically you could even make use of the php code option for "display output" on the computed field to cook up some dynamic output. That can force custom processing on display even for "db stored" fields.

Without further info it's hard to see what the best route would be for your specific application though. I'm marking this as a support request, as this is how Computed Field has always worked with Views, and it's noted on the front page of the project. Feel free to post specifics about your use case though if you want people to offer some ideas.

mmjvb’s picture

Issue summary: View changes
Status: Active » Closed (outdated)