How to save a field value according to another field value and with a user presave hook I'm using Drupal 8

There are field_a and field_b. I'd like to field_b have the same value with field_a but different format after user submit his user edit page.

my_module_user_presave($account)

{
 $data = $account-&gt;field_a-&gt;value; // There is no value, since this user did not save yet. This is the problem.
 $account-&gt;field_b-&gt;value=format($account-&gt;field_a);//format function will change the format of field_a value, and this is not a problem
}


Since the user did not save yet, so there is no value for field_a. So I am trying to use drupal_register_shutdown_function as below.

my_module_user_presave($account)

{
 drupal_register_shutdown_function('_my_module_user_presave',$account);
}
_my_module_user_presave($account)

{
 $data = $account-&gt;field_a-&gt;value;
 $account-&gt;field_b-&gt;value=format($account-&gt;field_a); //format will change the format of field_a value.
}


Now the field_a got the value. But field_b value will not be saved since drupal_register_shutdown_function.

What should I do?

Thanks!
To change a field according to another field:
function mymodule_user_presave($account) {

 $data = $account-&gt;field_a-&gt;value;
 $account-&gt;field_b-&gt;value = strtoupper($data);

 drupal_set_message($account-&gt;original-&gt;field_a-&gt;value . ' &gt; ' . $account-&gt;field_a-&gt;value);
 drupal_set_message($account-&gt;original-&gt;field_b-&gt;value . ' &gt; ' . $account-&gt;field_b-&gt;value);

}

To get the original values you would have to use $account-&gt;original. Otherwise you get the new values. To prove that it's working this is the output in messages from the code above after I entered abcdef in field_a:

abc &gt; abcdef
ABC &gt; ABCDEF
The changes have been saved.