You are here

function restrict_by_ip_user_profile_submit in Restrict Login or Role Access by IP Address 8.4

Same name and namespace in other branches
  1. 6.3 restrict_by_ip.module \restrict_by_ip_user_profile_submit()
  2. 7.3 restrict_by_ip.module \restrict_by_ip_user_profile_submit()

Custom submit function for the user_profile_form page.

1 string reference to 'restrict_by_ip_user_profile_submit'
restrict_by_ip_form_alter in ./restrict_by_ip.module
Implements hook_form_alter().

File

./restrict_by_ip.module, line 122
Restrict logins or roles to whitelisted IP addresses.

Code

function restrict_by_ip_user_profile_submit($form, &$form_state) {
  $config = \Drupal::service('config.factory')
    ->getEditable('restrict_by_ip.settings');
  $user = $form_state
    ->getFormObject()
    ->getEntity();
  $ips = $form_state
    ->getValue('restrict_by_ip_address');
  if (strlen($ips) > 0) {
    $config
      ->set('user.' . $user
      ->id(), $ips)
      ->save();
  }
  else {
    $config
      ->clear('user.' . $user
      ->id())
      ->save();
  }
}