- Status changed to Fixed
over 1 year ago 11:13pm 14 April 2023 Automatically closed - issue fixed for 2 weeks with no activity.
In a custom SocialAuthEvents::USER_FIELDS event subscriber, I attempt to get the first name of the social auth user and store it in a separate field. But I receive this error:
Typed property Drupal\social_auth\User\SocialAuthUser::$firstName must not be accessed before initialization
Create a custom SocialAuthEvents::USER_FIELDS event subscriber and attempt to access the social auth user first name. For example,
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = [];
$events[SocialAuthEvents::USER_FIELDS][] = ['onUserFields'];
return $events;
}
/**
* Populates name fields before user creation.
*
* @var \Drupal\social_auth\Event\UserFieldsEvent $event
* The event to respond to.
*/
public function onUserFields(UserFieldsEvent $event) {
$fields = $event->getUserFields();
$user = $event->getSocialAuthUser();
$first_name = $user->getFirstName();
Fixed
4.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Automatically closed - issue fixed for 2 weeks with no activity.