0

I have made a custom field for user field_custom_xyz from the admin GUI. Now after i saved it i got two tables into the database : one for data and one for revisions.
I already have a huge database into which a lot of users are already there.

I have two questions :

  1. How can i make sure that i can assign default value to each user at the time of creation of this field?
  2. Let's say if i have to assign a default value of 0 (or null in case i don't follow step 1).
    how can i change that value at the time of new registration using hook_user_presave ?

I want to override the default value of this field using user_presave hook in some custom module lets say 'abc' module

so far i have tried :

$account->field_custom_abc['und'][0]['value'] = 0;

but that doesn't work, any suggestions. thanks in advance.

1 Answer 1

1

Try this out:

/**
 * Implements hook_user_presave().
 */
function mymodule_user_presave(&$edit, $account, $category) {
  $edit['field_custom_xyz'][LANGUAGE_NONE][0]['value'] = 0;
}
1
  • Good, glad that help .
    – berramou
    Commented Nov 13, 2018 at 10:03

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.