abstract class UserManager in Social API 3.x
Same name and namespace in other branches
- 8.2 src/User/UserManager.php \Drupal\social_api\User\UserManager
Manages database related tasks.
Hierarchy
- class \Drupal\social_api\User\UserManager implements UserManagerInterface
Expanded class hierarchy of UserManager
File
- src/
User/ UserManager.php, line 12
Namespace
Drupal\social_api\UserView source
abstract class UserManager implements UserManagerInterface {
/**
* The Drupal Entity Manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The Messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* The Drupal logger factory.
*
* @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
*/
protected $loggerFactory;
/**
* The entity type.
*
* @var string
*/
protected $entityType;
/**
* The implementer plugin id.
*
* @var string
*/
protected $pluginId;
/**
* Constructor.
*
* @param string $entity_type
* The entity table.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Used for loading and creating Social API-related entities.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* Used to display messages to user.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
* Used for logging errors.
*/
public function __construct($entity_type, EntityTypeManagerInterface $entity_type_manager, MessengerInterface $messenger, LoggerChannelFactoryInterface $logger_factory) {
$this->entityType = $entity_type;
$this->entityTypeManager = $entity_type_manager;
$this->messenger = $messenger;
$this->loggerFactory = $logger_factory;
}
/**
* {@inheritdoc}
*/
public function getPluginId() {
return $this->pluginId;
}
/**
* {@inheritdoc}
*/
public function setPluginId($plugin_id) {
$this->pluginId = $plugin_id;
}
/**
* {@inheritdoc}
*/
public function getDrupalUserId($provider_user_id) {
try {
/** @var \Drupal\social_api\Entity\SocialApi[] $user */
$user = $this->entityTypeManager
->getStorage($this->entityType)
->loadByProperties([
'plugin_id' => $this->pluginId,
'provider_user_id' => $provider_user_id,
]);
if (!empty($user)) {
return current($user)
->getUserId();
}
} catch (\Exception $ex) {
$this->loggerFactory
->get($this
->getPluginId())
->error('Failed to to query entity. Exception: @message', [
'@message' => $ex
->getMessage(),
]);
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UserManager:: |
protected | property | The entity type. | |
UserManager:: |
protected | property | The Drupal Entity Manager. | |
UserManager:: |
protected | property | The Drupal logger factory. | |
UserManager:: |
protected | property | The Messenger service. | |
UserManager:: |
protected | property | The implementer plugin id. | |
UserManager:: |
public | function |
Gets the Drupal user id based on the provider user id. Overrides UserManagerInterface:: |
|
UserManager:: |
public | function |
Gets the implementer plugin id. Overrides UserManagerInterface:: |
|
UserManager:: |
public | function |
Sets the implementer plugin id. Overrides UserManagerInterface:: |
|
UserManager:: |
public | function | Constructor. |