Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use DrupaluserEntityUser;
- use SymfonyComponentHttpFoundationRedirectResponse;
- use DrupalCoreUrl;
- function whishlistt_user_login(DrupaluserUserInterface $account) {
- $roles = $account->getRoles();
- $user_id = Drupal::currentUser()->id();
- if(in_array('test', $roles)){
- $query_get_product_name = db_select('mydata', 'c');
- $query_get_product_name->fields('c', ['uid']);
- $result = $query_get_product_name->execute()->fetchAllAssoc('uid');
- if(!empty($result)) {
- $path = Url::fromRoute('user.logout', [], ['absolute' => TRUE])->toString();
- $response = new RedirectResponse($path);
- return $response->send();
- }
- else {
- $connection = Drupal::database();
- $result = $connection->insert('mydata')
- ->fields(['uid'])
- ->values([
- 'uid' => $user_id,
- ])
- ->execute();
- }
- }
- }
- function hook_user_logout($account) {
- //to be done
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement