Domanda

I am trying to get the user profile loaded with entity_metadata_wrapper:

$user_profile = entity_metadata_wrapper('user', $uid);
dpm($user_profile);

but I get nothing back. The user fields load fine with user_load($uid); What am I doing wrong?

È stato utile?

Soluzione 2

entity_metadata_wrapper expects second parameter to be an object, in this case, user object. According to your variable naming, it seems that you are passing user id instead. You can use user_load to fetch user object by ID.

Altri suggerimenti

The information provided by Linas is provably incorrect. The use of entity_metadata_wrapper with an entity id is completely okay. The function uses uid internally only if you pass an object to it to begin with, otherwise it passes the argument directly to EntityDrupalWrapper.

Eventually the set method will be called, which states: "Overridden to support setting the entity by either the object or the id."

This basic code will demonstrate a working call to entity_metadata_wrapper with just a user id.

$wrapper = entity_metadata_wrapper('user', 1);
dpm($wrapper->value());

The output will be an array of all the data belonging to the admin user.

The problem you are having is unrelated to your arguments being passed in (assuming $uid is valid), and requires more information to troubleshoot.

I have the same problem the code not work return empty (Object) EntityDrupalWrapper

global $user;
$user_profile = entity_metadata_wrapper('user', $user->uid);
dpm($user_profile);

But that code work well and return (Object) stdClass with all users fields like name password and other

global $user;
$user = user_load($user->uid);
$wrapper = entity_metadata_wrapper('user', $user);
dpm($wrapper->value());
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top