You are here

public function UserManager::getAccounts in Social Post 3.x

Same name and namespace in other branches
  1. 8.2 src/User/UserManager.php \Drupal\social_post\User\UserManager::getAccounts()

Gets the Social Post records associated with a user and a provider.

Parameters

string $plugin_id: The plugin for which to get the accounts.

string|null $user_id: The Drupal user ID.

Return value

\Drupal\social_post\Entity\SocialPost[] An array of Social Post records associated with the user.

File

src/User/UserManager.php, line 122

Class

UserManager
Manages database related tasks.

Namespace

Drupal\social_post\User

Code

public function getAccounts($plugin_id, $user_id = NULL) {
  $storage = $this->entityTypeManager
    ->getStorage($this->entityType);
  if (!$user_id) {
    $user_id = $this->currentUser
      ->id();
  }

  // Get the accounts associated to the user.
  $accounts = $storage
    ->loadByProperties([
    'user_id' => $user_id,
    'plugin_id' => $plugin_id,
  ]);
  return $accounts;
}