public function DefaultProfileLoad::resolve in Open Social 10.0.x
Same name and namespace in other branches
- 10.1.x modules/social_features/social_profile/src/Plugin/GraphQL/DataProducer/DefaultProfileLoad.php \Drupal\social_profile\Plugin\GraphQL\DataProducer\DefaultProfileLoad::resolve()
Resolve to a value.
Parameters
\Drupal\Core\Session\AccountInterface $account: The account to fetch the profile for.
\Drupal\Core\Cache\RefinableCacheableDependencyInterface $metadata: Cacheability metadata.
Return value
\GraphQL\Deferred|null A promise that resolves to the loaded profile or null if the user does not have a published profile.
File
- modules/
social_features/ social_profile/ src/ Plugin/ GraphQL/ DataProducer/ DefaultProfileLoad.php, line 104
Class
- DefaultProfileLoad
- Loads the default profile for a user.
Namespace
Drupal\social_profile\Plugin\GraphQL\DataProducerCode
public function resolve(AccountInterface $account, RefinableCacheableDependencyInterface $metadata) {
$storage = $this->entityTypeManager
->getStorage('profile');
$type = $storage
->getEntityType();
$query = $storage
->getQuery()
->currentRevision()
->accessCheck()
->condition('uid', $account
->id())
->condition('type', 'profile')
->condition('status', TRUE)
->sort('is_default', 'DESC')
->sort('profile_id', 'DESC')
->range(0, 1);
$metadata
->addCacheTags($type
->getListCacheTags());
$metadata
->addCacheContexts($type
->getListCacheContexts());
$result = $query
->execute();
if (empty($result)) {
return NULL;
}
$resolver = $this->entityBuffer
->add('profile', reset($result));
return new Deferred(function () use ($resolver, $metadata) {
$entity = $resolver();
$metadata
->addCacheableDependency($entity);
return $entity;
});
}