1

I am not able to access the fields of a bundle using entity metadata wrappers.Here is what I am doing.

//Entity Obj is the loaded entity object which contains a bundle whose fields I am trying to access
$entity_obj; 
$wrapper = entity_metadata_wrapper('theentitytype',$entity_obj,array('bundle'=>'thebundlename'));

But I am not able to see the fields of the bundle after doing this.The metadata wrapper function says the bundle_type should be mentioned as key = 'bundle' and value='bundle_name' inside of an array like which I am doing.

What am I doing wrong here?

  • What do you mean by "see the fields" exactly? Fields and properties are only discoverable by magic methods on an metadata wrapper so are you saying $wrapper->getPropertyInfo() is empty? Or perhaps you just weren't aware of the magic methods and getting confused because you don't see fields when you `var_dump' the object? – Clive Nov 8 '14 at 11:11
  • Well kind of both confused and I am not able to see the fields when doing getPropertyInfo().I can see that I need to get one level further from the entity to the bundle and then get the fields of it, which I am unable to do. – Wang Liqin Nov 8 '14 at 11:33
  • 1
    Not sure what's going wrong then, this works fine for me: entity_metadata_wrapper('node', NULL, array('bundle' => 'article'))->getPropertyInfo(). That array contains the expected fields. Did you read this part of the docs for bundle? If an entity is wrapped but not passed, use this key to specify the bundle to return a wrapper for. If you have a loaded entity object you shouldn't use that property – Clive Nov 8 '14 at 23:58

Your Answer

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

Browse other questions tagged or ask your own question.