Below is a hook from the LinkedIn Integration module.

Then I have a hook form alter in my module and it's all setup and ready to go to call a submit handler.

When the user goes to authorize LinkedIn, and come back, I want to fire some my code.

The question is I don't know what states or values are after it comes back. I tried this

function my_module_form_link($form,$form_state, $uid)

but it did not return anything

function linkedin_user_enable_form($form, $form_state, $uid) {
  $form = array();
  $form['#user'] = $uid;
  $form['#action'] = url('linkedin/token/' . $uid);
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Go to LinkedIn'),
    '#suffix' => '<p class="description">' . t('You will be taken to the LinkedIn website in order to complete the process.') . '</p>',
  return $form;

1 Answer 1


Looking at the linkedin module source code, there's some ways that can run code on the way back (but only when are logging-in, it seems).

When they are logging-in:

  1. hook_linkedin_external_login: if they don't already have an account and will be asked to register.
  2. hook_linkedin_tie_external_login: if they already have an account and will be logged-in using that account.

When they are associating a linkedin account:

  • I do not see any hooks or any stable way of running code in this case.

Here's an example on how to hook into hook_linkedin_external_login:

In your mymodule.module file:

function mymodule_linkedin_external_login($uid) {
  // do something

But you'll have to be careful since linkedin_auth_linkedin_external_login does a drupal_goto() so you'll have to have your module hook called first, so that your function doesn't get skipped. See how drupal decide execution order of same hook in different modules?

  • This isn't for login, it is for when they auth in their profile.
    – GreenLion
    Commented Jan 29, 2016 at 20:05
  • You mean when linking their linked-in account through their Drupal profile? In that case, that's my second section above, there's no obvious way to trigger code or hook onto something.
    – Weboide
    Commented Jan 29, 2016 at 20:11
  • Take a look at linkedin.inc module_invoke_all('linkedin_external_login', $uid); that calls a function in linkedin_auth.module function linkedin_auth_linkedin_external_login($uid) can I do anything with that?
    – GreenLion
    Commented Jan 29, 2016 at 20:49
  • Yes this is the first hook I mention in my answer, I've added an example on how to use that hook.
    – Weboide
    Commented Feb 1, 2016 at 12:56
  • I tried using using this, but when I login, I don't get a message. function module_linkedin_external_login($form,$form_state) { global $user; $account = user_load($user->uid); drupal_set_message(t('Hello - Login Worked')); } ALSO I set the weight to -1
    – GreenLion
    Commented Feb 1, 2016 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.