You are here

function notify_user_insert in Notify 2.0.x

Same name and namespace in other branches
  1. 8 notify.module \notify_user_insert()
  2. 7 notify.module \notify_user_insert()
  3. 1.0.x notify.module \notify_user_insert()

Implements hook_ENTIY_TYPE__insert().

File

./notify.module, line 119
Hooks for Notify module.

Code

function notify_user_insert(User $account) {
  $uid = $account
    ->id();
  $config = \Drupal::config('notify.settings');
  $id = \Drupal::database()
    ->insert('notify')
    ->fields([
    'uid' => $uid,
    'status' => $config
      ->get('notify_reg_default'),
    'node' => $config
      ->get('notify_def_node'),
    'comment' => $config
      ->get('notify_def_comment'),
  ])
    ->execute();

  // Get permitted node types.
  $nodetypes = $config
    ->get('notify_nodetypes');
  if ($nodetypes != NULL) {
    foreach ($nodetypes as $ntype => $value) {
      if ($value) {
        \Drupal::database()
          ->insert('notify_subscriptions')
          ->fields([
          'uid' => $uid,
          'type' => $ntype,
        ])
          ->execute();
      }
    }
  }
}