Created
September 6, 2017 14:35
-
-
Save japicoder/6888124db2a5611c881cd8f763f5b454 to your computer and use it in GitHub Desktop.
Drupal 8 - How to retrive the profile of an user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The following example allows to obtain the profile of a given user. | |
* | |
* @param $user \Drupal\Core\Session\AccountInterface | |
* User or UserSession object. | |
* @param $profile_type string | |
* Bundle type of the profile. | |
static function getUserProfile(AccountInterface $user, $profile_type) { | |
$profile = $this->profile_storage->loadByUser($user, $profile_type); | |
$entity_type_manager = \Drupal::entityTypeManager(); | |
$profile_entity_type = $entity_type_manager->getDefinition('profile'); | |
$profile_storage = ProfileStorage::createInstance(\Drupal::getContainer(), $profile_entity_type); | |
$profile = $profile_storage->loadByUser($user, $profile_type); | |
return $profile; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment