You are here

function blogapi_blogger_get_user_info in Blog API 8

Same name and namespace in other branches
  1. 7.2 modules/blogapi_blogger/blogapi_blogger.module \blogapi_blogger_get_user_info()
  2. 7 blogapi.module \blogapi_blogger_get_user_info()

Callback for blogger.getUserInfo.

Parameters

$hash: Unused value.

$username: Drupal username.

$pass: Drupal password.

Return value

array Return formatted array of user info.

1 string reference to 'blogapi_blogger_get_user_info'
BloggerProvider::getMethods in modules/blogapi_blogger/src/Plugin/BlogapiProvider/BloggerProvider.php
Returns implemented methods.

File

modules/blogapi_blogger/blogapi_blogger.module, line 107

Code

function blogapi_blogger_get_user_info($hash, $username, $pass) {
  $communicator = \Drupal::service('service.communicator.blogapi');
  $user = $communicator
    ->authenticate($username, $pass, TRUE);
  if (!$user) {
    return $communicator
      ->returnXmlError($communicator::BLOGAPI_XML_ERROR_AUTH);
  }
  $uid = $user
    ->id();
  $name = $user
    ->getDisplayName();
  $email = $user
    ->getEmail();
  $url = Url::fromUri('internal:/user/' . $uid)
    ->setAbsolute();
  $strings = [];
  if (is_string($name)) {
    $strings = explode(' ', $name);
  }
  return [
    'userid' => $uid,
    'firstname' => isset($strings[0]) ? $strings[0] : $username,
    'lastname' => isset($strings[1]) ? $strings[1] : '',
    'nickname' => $username,
    'email' => $email,
    'url' => $url
      ->toString(),
  ];
}