Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. use DrupaluserEntityUser;
  2. use SymfonyComponentHttpFoundationRedirectResponse;
  3. use DrupalCoreUrl;
  4.  
  5.  
  6. function whishlistt_user_login(DrupaluserUserInterface $account) {
  7.  
  8. $roles = $account->getRoles();
  9. $user_id = Drupal::currentUser()->id();
  10.  
  11.  
  12. if(in_array('test', $roles)){
  13.  
  14. $query_get_product_name = db_select('mydata', 'c');
  15. $query_get_product_name->fields('c', ['uid']);
  16. $result = $query_get_product_name->execute()->fetchAllAssoc('uid');
  17. if(!empty($result)) {
  18. $path = Url::fromRoute('user.logout', [], ['absolute' => TRUE])->toString();
  19. $response = new RedirectResponse($path);
  20. return $response->send();
  21. }
  22. else {
  23. $connection = Drupal::database();
  24. $result = $connection->insert('mydata')
  25. ->fields(['uid'])
  26. ->values([
  27. 'uid' => $user_id,
  28. ])
  29. ->execute();
  30. }
  31.  
  32. }
  33. }
  34.  
  35. function hook_user_logout($account) {
  36. //to be done
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement