You are here

function ip_entity_insert in IP address manager 8.2

Implements hook_entity_insert().

File

./ip.module, line 24
IP address manager module.

Code

function ip_entity_insert(Drupal\Core\Entity\EntityInterface $entity) {
  switch ($entity
    ->getEntityTypeId()) {
    case 'user':

      // Track anonymous registration (Do not track administration account creation).
      if (Drupal::currentUser()
        ->id() == 0 || Drupal::currentUser()
        ->id() == $entity
        ->id()) {
        $ipTracker = new IpTracker(Database::getConnection(), Drupal::request(), $entity);
        $ipTracker
          ->save();
      }
      break;
    default:

      // @TODO: allow selection of entities to be tracked.
      $ipTracker = new IpPosts(Database::getConnection(), Drupal::request(), $entity);
      $ipTracker
        ->save();
  }
}