1

I have this little problem with a custom field that is bundled with user. In its validation function I need to have access to the user id of the user whose field is being edited.

What that means is, when I edit a user, I need to get his uid in the validation function.

The problem is that hook_field_validate provides just $entity variable that doesn't include uid.

I know I could load the user object using his email / name (and then retrieve the uid from it) but it wouldn't properly work when email/name was being changed (I could get only the changed values from $entity and therefore wouldn't be able to load the object properly).

Any ideas?

2
  • So the field is on a the user entity type (in hook_field_validate $entity_type == 'user'), but $entity->uid is empty for edits to existing users?
    – mpdonadio
    Apr 5, 2014 at 19:03
  • Yep, it's exactly as you say.
    – Petrroll
    Apr 5, 2014 at 19:07

1 Answer 1

1

You can always get this information from the path, eg:

// you are sitting on user/#/edit

$uid=arg(1);                      // quick, or...
$account=menu_get_object('user'); // the full user object, eg the uid is in $account->uid

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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