Back in the day, drupal 7 had quite a useful way of stashing (occasionally arbitrary) values in the database. Remember…
In Drupal 8, these functions have been replaced with ‘the new configuration system API/storage’. You can read about that here. But, there is more…
There is a nice way to set and get user data in drupal 8. We can make use of the users_data table. Take a look, it’s more than likely empty. Here is the set method:
$userData = \Drupal::service('user.data');
$userData->set('my_module', $uid, 'a_key', 'Here is a value');
And to get the data:
$data = $userData->get('my_module', $uid, 'a_key');
It’s still definitely worth learning about the new configuration system API for Drupal 8, but this is nice one to keep in the toolbox!