2

I'm using Location module (particularly its Location CCK part) with Drupal 7. Added location field 'field_location' to User (as an example of hosting entity), and initialized location values for test users in user edit interface. However, I'm unable to access location data of the current user:

global $user;
$user_id = $user->uid;

$loc = $user->field_location;

or:

$wrapper = entity_metadata_wrapper('user', $user_id);
$loc = $wrapper->field_location;

The statements with $loc don't work for object and wrapper (while both user object and wrapper are initialized successfully). Same for:

$loc = $wrapper->field_location[0];
$loc = $wrapper->field_location->raw();

I've read a number of posts on this topic, however haven't found a workable solution, would appreciate insights on this.

0
1
+50

For a custom field to be available to the wrapper, the module defining it needs to implement hook_entity_property_info() (or, which is new to me, by adding property metadata to the field using hook_field_info_alter()).

The location_cck module doesn't do that, but the bundled location_entity module does.

If you enable that module you should be able to access the location field as you'd expect.

0

What about loading the user?

$my_user = user_load($user->uid);

Then you should be able to access all fields of the user...

1
  • global $user; should be providing the user object for the currently logged in user. – David Csonka Nov 15 '13 at 21:54

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.