How to implement a custom hook I have implemented a custom login module and I want to keep it on general purpose state.

This module have been developed because users can be authenticate against an internal LDAP Server (Sun Microsystems' LDAP directory server). So in this module I want to keep only the authentication and retrieve data from the LDAP directory. That's fine, I have it, within the PHP API (LDAPc) we have available.

There are situations where the link to log into the application comes with extra querystring parameters, and I have the thought to add a hook to my custom login module, so from other module I can implement that custom hook, retrieve these querystring and do whatever we need to do... add them in an extra table linked with the user table, for example.

I could do this inside the custom login module, but if so, my module will not be valid for other drupal sites with other needs.

My first thought, following this post: http://tylerfrankenstein.com/code/drupal-create-custom-hook-for-other-modules

has been to add the lines:

    $params = $_GET;
    drupal_alter('retrieve_login_extra_params', $params);


to my current development state

/**
 * Implements hook_menu().
 */
function psaldaplogin_menu()
{
    $items = array();
    // Login Page to authenticate against PSA Ldap directory
    $items['user/psaldaplogin'] = array(
            // Every user can access to this page
            'access callback' =&gt; TRUE,
            // Define the function where implement the generation of the page
            'page callback' =&gt; '_psaldaplogin_view',
    );
    return $items;
}



/**
 * Authentication procedure
 *
 * TODO:
 *     Allow other modules implement this process as a hook, 
 *     so more complex process on login step
 *     could be implemented outside this module
 *
 */
function _psaldaplogin_view()
{
    // Clear messages queue
    drupal_get_messages();

    // Check if the user is already logged
    if (user_is_logged_in()) {
        drupal_goto('home');
    }

    // Allow other modules process the querystring parameters
    // --&gt; DOESN'T WORK
    $params = $_GET;
    drupal_alter('retrieve_login_extra_params', $params);

    // Authorized the user
    if ($username = _getAuthorizedUser()) {
        // Get the user information from PSA Ldap directory
        $userData = _getLdapUserInformation($username);
        // Register the user into Drupal
        if (_registerExternalUser($userData)) {
            // Redirecto to home
            drupal_goto('home');
        } else {
            // If the registration failed show access denied message
            drupal_access_denied();
        }
    } else {
        // If the authentication failed show access denied message
        drupal_access_denied();
    }
}


Figuring out I will be able from other module implement something like:

function slider_retrieve_login_extra_params($params)
{
    // check $params since they are unsafe data

    // test if the querystring params could be retrieve here
    file_put_contents('/tmp/genius/genius.log', 
        "\n" . print_r($params, true) . "\n", 
        FILE_APPEND);
}


But this chunk of code is never executed, so it is clear I have a miss understanding on how to allow other modules to implement a custom hook.

I'll appreciate if someone could point me to the right direction to achieve this solution. Otherwise I will have the module as template since for each development the login needs could be different.

Thanks for the reading.

Regards.
Putting aside the general design of your application, you are right to use drupal_alter to provide a hook.

However, you are missing the correct hook implementation function name.

It should be:

drupal_alter('retrieve_login_extra_params', $params);
// ...
function MODULE_retrieve_login_extra_params_alter(&amp;$params){
// ...
}


You may also be interested in:


LDAP Integration
user_external_login_register