You are here

function autosave_form_user_update in Autosave Form 8

Implements hook_entity_update() for the user entity type.

If the permissions of a user are changed, then we delete the autosave states belonging to that user. It is possible that new permissions the user is loosing the ability to access certain fields, but the autosave states contain data for them.

File

./autosave_form.module, line 134
This module holds autosave form functionality.

Code

function autosave_form_user_update(EntityInterface $user) {

  /** @var \Drupal\user\UserInterface $user */
  $current_roles = $user
    ->getRoles();
  $original_roles = $user->original
    ->getRoles();
  sort($current_roles);
  sort($original_roles);
  if ($current_roles !== $original_roles) {

    /** @var \Drupal\autosave_form\Storage\AutosaveEntityFormStorageInterface $autosave_entity_form_storage */
    $autosave_entity_form_storage = \Drupal::service('autosave_form.entity_form_storage');
    $autosave_entity_form_storage
      ->purgeAutosavedEntitiesStates(NULL, NULL, $user
      ->id());
  }
}