The following code produces an exception.

  $node = node_load($nid);
  $wrapper = entity_metadata_wrapper('node', $node);
  $field_value = $wrapper->field_my_computed_field->value();
EntityMetadataWrapperException: Unknown data property field_my_computed_field. in EntityStructureWrapper->getPropertyInfo()
(line 339 of .../sites/all/modules/entity/includes/entity.wrapper.inc).

However, other fields created using UI can be accessed using this method.
The Entity module become popular, it is better to add support for it.

Comments

skipyT’s picture

Hi,

I think the patch file from: http://drupal.org/node/1514848#comment-6049526 is fixing your issue also.

I made the modification to support the computed fields in the search api module, but it is the same fix.

BParticle’s picture

Hi,

Not sure if this is the right thread to post to, but as I'm using entity_metadata_wrapper maybe it is related. I am desperately trying to do simple calculations with some fields inside a field collection entity.

This is the code in the computed field area, I'm adding up the values of field_bar inside the collection field_student:

global $node;	
$meta_wrapper = entity_metadata_wrapper('node', $node);
$student_line = array();
foreach ($meta_wrapper->field_student as $line) {
  $student_line[] = $line->value()->field_bar;
}
$t = count($meta_wrapper->field_student);
$anotherarray = array();

for ($i = 0; $i < $t; ++$i) {
  $anotherarray[$i] = $student_line[$i]['und'][0]['value'];
}

$entity_field[0]['value'] = array_sum($anotherarray);

Although it's not perfect (due to undefined index errors for empty values), it works as intended when loaded from the node template. When I use the exact same code in the computed field however, there is no returned value. Is entity_metadata_wrapper actually supported in this way, is my code wrong? (I applied the patch on http://drupal.org/node/1514848#comment-6049526)

Any help most appreciated,

BP

skipyT’s picture

I don't think you can use entity metadata wrapper there, because the node is not fully loaded yet I think, if your computed field is on a node.

Perhaps your field is not loaded yet, that's why the exception.

BParticle’s picture

That makes sense, but then I don't know how to use this module.
Am I supposed to add a computed field to a different entity, using the field information of a target node? That seems rather far fetched. I thought the whole point of the module was that it enables you to make calculations with the information given by the user in the same form, on the same entity...

BParticle’s picture

@skipyT Just had a look at the initial code of this thread. It seems to be a different matter altogether so I will file a support request elsewhere. Thank you for answering.