1

For node I can use the entity_metadata_wrapper like below

function mymodule_node_presave($node) {
  $ewrapper = entity_metadata_wrapper('node', $node);
  $ewrapper->title->set('new title');
}

However how can I use the entity_metadata_wrapper for users. I want to use entity_metadata_wrapper in hook_user_presave.

function mymodule_user_presave(&$edit, $account, $category) {
  ???
}

this variant works for me:

function mymodule_user_presave(&$edit, $account, $category) {
  $edit_object = (object) $edit;
  $ewrapper = entity_metadata_wrapper('user', $edit_object);
  $field_telefon = $ewrapper->field_telefon->value();
  $ewrapper->field_telefon->set($field_telefon.'123');
  $edit = (array)$edit_object;
}

1 Answer 1

1

Try casting $edit as an object:

function mymodule_user_presave(&$edit, $account, $category) {
  $ewrapper = entity_metadata_wrapper('user', (object) $edit);
}
1
  • How to update user fields for an exisiting user using entity_metadata_wrapper? Commented Jun 23, 2016 at 18:35

Your Answer

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

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