I'm creating a user account programmatically using the code below (Drupal 8). Everything works well except when the user suppose to change their password via the Drupal generated 'one-time login link'. The password reset doesn't work and it seems the 'pass-reset-token' is not generated properly. What am I doing wrong?
public function submitForm(array &$form, FormStateInterface $form_state)
{
$the_user_email = $form_state->getValue('user_email');
$the_user_name = $form_state->getValue('user_name');
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$user = \Drupal\user\Entity\User::create();
$user->setPassword(user_password());
$user->enforceIsNew();
$user->setEmail($the_user_email);
$user->setUsername($the_user_name);
$user->set("init", $the_user_email);
$user->set("langcode", $language);
$user->set("preferred_langcode", $language);
$user->set("preferred_admin_langcode", $language);
$user->addRole('price_list_users');
$user->activate();
//Create the account
$user->save();
_user_mail_notify('register_no_approval_required', $user);
drupal_set_message($this->t('A welcome message with further instructions has been sent to your email address.'));
$form_state->setRedirect('/price-list');
}