function custom_user_update($account) {
  $user = \Drupal\user\Entity\User::load($account->id());
  $level = user->get('field_account_participation')->entity->tid->value;

Now I need to check my $level equals the post value of field_account_participation. How we can do this in Drupal8?

  • What are you trying to do? Work out if the value has changed? – Clive Feb 20 '18 at 14:34
  • Actually we don't have the option to collect the data for $form_state in hook_user_update, so i have tried in a different way to achieve this. – dev Mar 30 '18 at 8:35

As stated in the documentation of hook_entity_update() one could use $entity->original:

Get the original entity object from $entity->original.

So you could use this object to find out if your field value has changed by writing something like this:

function custom_user_update($account) {
  $user = \Drupal\user\Entity\User::load($account->id());
  $original_value = $account->original->get('field_account_participation')->entity->tid->value;
  $updated_value = $user->get('field_account_participation')->entity->tid->value;

  if ($original_value != $updated_value) {
    // Do something here...
| improve this answer | |

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.