You are here

function legal_user_update in Legal 2.0.x

Same name and namespace in other branches
  1. 8 legal.module \legal_user_update()
  2. 7.2 legal.module \legal_user_update()
  3. 7 legal.module \legal_user_update()

Implements hook_ENTITY_TYPE_update().

File

./legal.module, line 570
Module file for Legal.

Code

function legal_user_update(EntityInterface $entity) {
  if ($entity instanceof User) {
    $language = \Drupal::languageManager()
      ->getCurrentLanguage();
    $conditions = legal_get_conditions($language
      ->getId());
    if (empty($conditions['conditions'])) {
      return;
    }

    // Record the accepted state before removing legal_accept from $edit.
    $accepted = \Drupal::request()->request
      ->get('legal_accept') ? TRUE : FALSE;
    if (\Drupal::currentUser()
      ->id() != $entity
      ->get('uid')
      ->getString()) {
      return;
    }

    // If already accepted skip data entry.
    $previously_accepted = legal_version_check($entity
      ->get('uid')
      ->getString(), $conditions['version'], $conditions['revision']);
    if ($previously_accepted === TRUE) {
      return;
    }
    if ($accepted) {
      legal_save_accept($conditions['version'], $conditions['revision'], $conditions['language'], $entity
        ->get('uid')
        ->getString());
    }
  }
}