You are here

public function GetServices::getUserByUsername in Simple Node Importer 8

2 calls to GetServices::getUserByUsername()
GetServices::createNewUser in src/Services/GetServices.php
GetServices::prepareEntityReferenceFieldData in src/Services/GetServices.php

File

src/Services/GetServices.php, line 481

Class

GetServices

Namespace

Drupal\simple_node_importer\Services

Code

public function getUserByUsername(string $uname, $op = NULL) {

  // $op could be 'new', 'admin', 'current', 'content_validate'.
  $userId = \Drupal::entityQuery('user')
    ->condition('name', $uname)
    ->range(0, 1)
    ->execute();
  if (!empty($userId)) {
    return key($userId);
  }
  elseif ($op == 'new') {
    return $this
      ->createNewUser(NULL, $uname);
  }
  elseif ($op == 'admin') {
    $adminUid = 1;
    return $adminUid;
  }
  elseif ($op == 'current') {
    $userObj = \Drupal::currentUser();
    return $userObj;
  }
  elseif ($op == 'content_validate') {
    return NULL;
  }
  else {
    return NULL;
  }
}