You are here

function blogapi_blogger_get_users_blogs in Blog API 8

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

Callback for blogger.getUsersBlogs.

Parameters

$hash: Unused value.

$username: Drupal username.

$pass: Drupal password.

Return value

array Return formatted array of available content types.

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

File

modules/blogapi_blogger/blogapi_blogger.module, line 66

Code

function blogapi_blogger_get_users_blogs($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);
  }
  $content_type = $communicator->blogapiConfig
    ->get('content_types');
  if (empty($content_type)) {
    return [];
  }
  $return = [];
  foreach ($content_type as $type) {
    if ($type) {
      $url = Url::fromUri('internal:/user/' . $user
        ->id())
        ->setAbsolute();
      $return[] = [
        'url' => $url
          ->toString(),
        'blogid' => $type,
        'blogName' => $user
          ->getUsername() . ': ' . $type,
      ];
    }
  }
  return $return;
}