2

Is there a function to get parent enityinfo to which entityreference field is attached. Similar function is hostEntity() provided by field_collection.

I created the content type which has enityform as enitityreference field.Enityform contains basic contact field with additional computed field. In that field I need nid of node to which entityform is attached.Using entity_metadata_wrapper I am able to get info about entityform object using below code.

$wrapper = entity_metadata_wrapper($entity_type, $entity);  
$info=$wrapper->entityInfo();

Any idea how to further backtrack and get parent node id?

Update : Entityform is attached to a node(ref).
1.Node contains entity reference field, to which enitity form is attached.
2.Enityform contains computed field.
3.In computed field when the above mentioned code executed, field $wrapper gets the details about enitityform object(should be because computed field belongs to this entity).
4.As there will be no relation between node and the attached entityfrom after submission, I am trying to capture the NID of node during the form submission.

1

Check out this issue in Entityform queue https://drupal.org/node/2041349

This person had the same problem. You can do this without programming if you use the Entity Reference Current module.

You will need to attach an Entity Reference field to the Entityform Type and have the field use the Entity Reference current behavior.

  • ,nice catch. you are throwing me back to my own thread :). You get what i Mean ? ;). I was expecting some other alternative solutions from SO brains thats why I kept this issue open here. – kiranking Jul 19 '13 at 20:01
0

Something like this should work:

// Load wrapper
$wrapper = entity_metadata_wrapper($entity_type, $entity);  
// Load parent entity
$parent = $wrapper->field_entityreference->value();
// Get nid
$nid = $parent->field_computed_field->value();
// Debug output
drupal_set_message(t('Parent NID: @nid', array('@nid' => $nid)));
  • I think you misunderstood the question or information is not good enough. So I have updated the question with additional details. – kiranking Jul 16 '13 at 13:38

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.