I need to do a REST request every time a new user signs up.
The REST request returns some data that I need to store for the Drupal user account, and be able to present as content somewhere.
What is the best/cleanest way to do that?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI need to do a REST request every time a new user signs up.
The REST request returns some data that I need to store for the Drupal user account, and be able to present as content somewhere.
What is the best/cleanest way to do that?
You can do it in a simple custom module, be sure to first understand Drupal hooks system as this is the base for (almost) everything Drupal.
In your module, you can implement hook_user_presave()
to be called before a user account is saved. It will be called for both creation and update, so you will need to guard your code with a condition to detect new user. After the REST call, there is several option to store the returned data. The easiest one is the use the data attribute of the user account. It is a simple PHP array that will be serialized in a database columns. It is not very good performande wise and not very flexible (you can query the stored data) but it is easy.
function MODULE_user_presave(&$edit, $account, $category) {
// Accoding to user_save's documentation, this is a new user if
// $account->is_new is set to TRUE or if $account->uid is not set
if ($category == 'account' && (!empty($account->is_new) || !isset($account->uid)))) {
$edit['data']['MODULE'] = MODULE_get_data_from_rest($account);
}
}
A core feature in Drupal 7 is available that can trigger a specific action if a user is created, etc. You don't have to code to achieve this: