Commit 34dae3f5 authored by George's avatar George
Browse files

Issue #2979037 - Fix validation when editing an existing user.

parent b55a8938
Loading
Loading
Loading
Loading
+5 −0
Changes for fbl.module: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
 * Module file for the field based login module.
 */

use Drupal\user\Entity\User;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
@@ -76,11 +77,15 @@ function fbl_user_register_validate($form, FormStateInterface &$form_state) {
      $results = $query->execute();
      // If any results, let's throw error.
      if (count($results)) {
        // Get current user.
        $current_user = User::load(\Drupal::currentUser()->id());
        if ((!isset($results[$current_user->id()]) || $current_user->id() === 0) && !$current_user->hasPermission('administer users')) {
          $form_state->setErrorByName($field_name, t('The entered value already exists. Please enter a different value.'));
        }
      }
    }
  }
}

/**
 * Custom validate function to check custom user field records.