0

While trying to interate over file filed values, EMW cannot being created properly. using isset() for not iniated fields and then trying to set them is not helping.

I get the error:

EntityMetadataWrapperException: Unknown data property field_discipline. in EntityStructureWrapper->getPropertyInfo() (line 335 of /var/www/siradisisporlar.com/sites/all/modules/ssbasic/entity/includes/entity.wrapper.inc).

Note that file wrapper here is EntityStructureWrapper and node wrapper is EntityDrupalWrapper.

All properties of other entity reference fields, etc are being reached properly.

$filew::data is array and it has fid where $nodew::data is a proper node object.

mymodule_node_insert($node) {
  //.... ..... $nodew is node wrapper
  foreach ($nodew->field_media as $delta => $filew) {
    $a = $filew->field_taxonomy_entity_reference->value(); //error here
    $b = $nodew->field_taxonomy_entity_reference->value();
    $c = array_unique(array_merge($a, $b));
    $filew->field_taxonomy_entity_reference = $c; //error here
    $filew->save();
  }
}
  • Also, you cannot reach other fields of the file object here, like alt text or owner. – duru Apr 18 '15 at 21:10
  • $filew->getIdentifier() also comes null. – duru Apr 19 '15 at 11:05
1

Sadly, I am posting a very bad workaround for future reference. Anybody who can improve this is welcome:

function mymodule_node_insert($node) {
  //copy terms
  $nodew = entity_metadata_wrapper('node', $node);
  //@todo this is not cool, figure it out
  foreach ($nodew->field_media->value() as $delta => $files) {
    $filew = entity_metadata_wrapper('file', $files['fid']);
    $filew->field_taxonomy_entity_reference = array_unique(array_merge($filew->field_taxonomy_entity_reference, $nodew->field_taxonomy_entity_reference));
    $filew->save();

  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.