You are here

function autologout_user_profile_submit in Automated Logout 8

Same name and namespace in other branches
  1. 6.4 autologout.module \autologout_user_profile_submit()
  2. 7.4 autologout.module \autologout_user_profile_submit()

Handle submission of timeout threshold in user/edit.

1 string reference to 'autologout_user_profile_submit'
autologout_form_user_form_alter in ./autologout.module
Implements hook_form_FORM_ID_alter().

File

./autologout.module, line 81
Automated Logout - Module.

Code

function autologout_user_profile_submit(&$form, FormStateInterface $form_state) {
  $user = \Drupal::currentUser();
  $user_id = $form_state
    ->getFormObject()
    ->getEntity()
    ->id();
  $access = FALSE;

  // If user-specific thresholds are enabled (the default), and user has access
  // to change and they are changing their own and only
  // their own timeout, or they are an admin.
  if (!\Drupal::currentUser()
    ->isAnonymous() && ($user
    ->hasPermission('change own logout threshold') && $user
    ->id() == $user_id || $user
    ->hasPermission('administer autologout'))) {
    $access = TRUE;
  }

  // Access is reused here as a security measure. Not only will the element not
  // display but wont submit without access.
  // Do not store config if setting to not store config for every user is TRUE.
  if ($access && !\Drupal::config('autologout.settings')
    ->get('no_individual_logout_threshold')) {
    $timeout = $form_state
      ->getValue('user_' . $user_id);
    \Drupal::service('user.data')
      ->set('autologout', $user_id, 'timeout', $timeout);
  }
  \Drupal::service('user.data')
    ->set('autologout', $user_id, 'timeout', $timeout);
}