autologout.api.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * @file
  4. * Describe hooks provided by the autologout module.
  5. */
  6. /**
  7. * Prevent autologout logging a user out.
  8. *
  9. * This allows other modules to indicate that a page should not be included
  10. * in the autologout checks. This works in the same way as not ticking the
  11. * enforce on admin pages option for autologout which stops a user being logged
  12. * out of admin pages.
  13. *
  14. * @return bool
  15. * Return TRUE if you do not want the user to be logged out.
  16. * Return FALSE (or nothing) if you want to leave the autologout
  17. * process alone.
  18. */
  19. function hook_autologout_prevent() {
  20. // Don't include autologout JS checks on ajax callbacks.
  21. $path_args = explode('/', current_path());
  22. $blacklist = [
  23. 'ajax',
  24. 'autologout_ahah_logout',
  25. 'autologout_ahah_set_last',
  26. ];
  27. if (in_array($path_args[0], $blacklist)) {
  28. return TRUE;
  29. }
  30. }
  31. /**
  32. * Keep a login alive whilst the user is on a particular page.
  33. *
  34. * @return bool
  35. * By returning TRUE from this function the JS which talks to autologout
  36. * module is included in the current page request and periodically dials back
  37. * to the server to keep the login alive.
  38. * Return FALSE (or nothing) to just use the standard behaviour.
  39. */
  40. function hook_autologout_refresh_only() {
  41. // Check to see if an open admin page will keep login alive.
  42. if (\Drupal::service('router.admin_context')->isAdminRoute(routeMatch()->getRouteObject()) && !\Drupal::config('autologout.settings')->get('enforce_admin')) {
  43. return TRUE;
  44. }
  45. }