You are here

function legal_user_insert in Legal 8

Same name and namespace in other branches
  1. 7.2 legal.module \legal_user_insert()
  2. 7 legal.module \legal_user_insert()
  3. 2.0.x legal.module \legal_user_insert()

Implements hook_ENTITY_TYPE_insert().

File

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

Code

function legal_user_insert(EntityInterface $entity) {
  $language = \Drupal::languageManager()
    ->getCurrentLanguage();
  if ($entity instanceof User) {
    $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;

    // Don't insert if user is already registered (administrator).
    if (\Drupal::currentUser()
      ->id() != 0) {
      return;
    }
    if ($accepted) {
      legal_save_accept($conditions['version'], $conditions['revision'], $conditions['language'], $entity
        ->get('uid')
        ->getString());
    }
  }
}