Advanced Customization - Hooks

Skip to end of metadata
Go to start of metadata

Overview

The Gigya module provides a set of hooks that enables you to dynamically change variable values that are passed to Drupal and/or override Gigya module functionality.

Every Gigya API call that is invoked by the module goes through “drupal_alter” functions before being sent to Gigya's servers. To interact with or extend the Gigya module, simply implement corresponding hooks in your own module code. For each hook, the prefix 'hook' in the name of the function is a placeholder for the name of your module. For example, if you want to implement a hook to modify the global conf object, and your module is called 'my_module', implement a function called my_module_gigya_global_conf_alter($gigya_js_settings);

For more information on how the hooks work, see drupal_alter method documentation and Drupal hooks documentation.

Sample module: For an example of how to implement these hooks in your own code, download our sample "Gigya Client" module, which includes an example of using the gigya_raas_create_user_alter hook. Review the code and use the module as a reference for your own hook implementations.

 

Available Hooks 

The following table describes the hooks available in the Gigya module.

All these hooks are included in the file {modules install dir}/gigya/gigya.api.php.

Whenever available, the $context parameter fields are derived from the 'hook_field_formatter_view' parameters.

NameParametersDescription
hook_gigya_global_conf_alter
  • &$gigya_js_settings

Alter Gigya global configuration parameters, e.g. the list of social network and other identity providers, or the interface language. See all available parameters in the Global Conf documentation. Note that these parameters are not handled as standard Drupal JavaScript settings, but instead are included as an object in the HTML head section of the page.

hook_notify_login_user_info_alter
  • &$gigya_user_info

This hook is called before calling Gigya's notifyLogin API method. The parameter &$gigya_user_info passed to the hook function is the user info that will be sent to Gigya. You can use and alter the following fields before they are sent: nickname, photoURL, thumbnailURL, firstName, lastName, gender, age, email.

hook_gigya_create_user_alter
  • &$form_state
  • $bio

Alter parameters for a new user when it is created via Gigya login. The parameters that are passed to the alter function are:

  • $form_state - the form that gets sent to Drupal as the new user registration form 
  • $bio - the Gigya user object as it is returned from the Gigya onLogin event.
hook_gigya_loginui_alter
  • &$gigya_login_params
This hook alters the Gigya socialize.showLoginUI configuration parameters before they are added to the Javascript settings. A list of available parameters can be found in the API method documentation page.
hook_gigya_connectui_alter
  • &$gigya_connect_params
This hook is called to alter parameters of the gigya.socialize.showAddConnectionsUI method before adding it to the Javascript settings. A list of available parameters can be found in the method's API page.
hook_gigya_tokens_alter
  • &$replacements
  • $tokens
  • $gigya_user_info

This hook is run before the Gigya tokens are returned. Other modules can implement this hook to changes values provide by Gigya or to add values.Use $replacements as a key->value set for altering the available $tokens. For more information click here.

Valid fields for the $ gigya_user_info param are  nickname, photoURL, thumbnailURL, firstName, lastName, gender, age, email .

Hooks Related to Gigya RaaS
hook_gigya_raas_create_user_alter
  • &$new_user_array
  • $gigya_info
This hook lets other modules modify the user array before it is sent to the user save function when a user is created via RaaS. The first parameter is the array that would be sent to the user_save function. The second one is the parameter is the info passed from Gigya on the getAccountInfo response data.
hook_gigya_raas_update_user_alter
  • &$edit
  • $user
  • $gigya_info

This hook is called after the user logs in to the site using RaaS. Use it to alter user data before it is sent to the server.

  • The $edit parameter is in place of the $new_user_array sent to the user save function.
  • $user holds the parameters to be changed.
  • $gigya_info is the info passed from Gigya on the getAccountInfo response data .
hook_gigya_get_account_info_alter
  • &$req_params

This hook enables you to add parameters to the user info request so it could be used later in the field mappings.

The following example adds the hometown to the user info request:

$req_params['extraProfileFields'] = "username,hometown";

Available parameters can be found on the accounts.getAccountInfo page.

hook_gigya_raas_create_profile2_alter
  • &$profile
  • $gigya_account

This hook is called after the user logs in to the site using RaaS. Allows others to alter the profile2 object fields upon user creation.

hook_gigya_raas_update_profile2_alter
  • &$profile
  • $gigya_account

This hook is called after the user logs in to the site using RaaS. Allows others to alter the profile2 object fields upon user update/login.

  • $profile the profile2 object.
  • $gigya_account the gigya account array as retread from gigya getAccountInfo.
hook_gigya_login_register_response_alter
  • &$commands
  • $ctx
  • $drupal_user
  • $gigya_user

This hook is used to differentiate between a returning user (login event) and a new user (registration event). An example of using such a hook is to redirect new users to one page ('Thank you!') and returning users to another ('Welcome Back!').

  • $commands is an array of ajax commands returned to the browser
  • $ctx is an array that provides the context. The keys are:
    • result can be success or error of login
    • type: the type of error, if there was one. Possible types include:
      • gigya_api_error: Error calling Gigya
      • missing_email: Gigya user is missing an email
      • drupal_error: Error saving user to Drupal
      • has_bypass: User has bypass_gigya_raas permission
      • invalid_signature: The UID signature was invalid
    • drupal_mode: create means this is a new user. login means the user exists in the Drupal database.
  • $drupal_user and $gigya_user are the Drupal / Gigya user object, and are returned only if registration/login were succesful
hook_gigya_profile_update_alter
  • &$edit
  • $user
  • $gigya_account

After a user updates their profile information in the Gigya account, use this hook to update the Drupal user object, before setting the user data in the Drupal database.

  • $edit: The changes made by the user to their Gigya profile (array)
  • $user: The Drupal user (object)
  • $gigya_account: The Gigya user account, as returned from accounts.getAccountInfo (array).
Hooks Related to the Gigya Plugins
hook_gigya_sharebar_alter
  • &$share_settings
  • $context
This hook is called before adding the socialize.showShareBarUI configuration parameters to the Javascript settings. A developer guide to the Share Bar plugin is available here.  A list of available parameters can be found in the showShareBarUI API documentation.
hook_gigya_reactions_alter
  • &$reactions_settings
  • $context
This hook is called before adding the socialize.showReactionsBarUI configuration parameters to the Javascript settings. A developer guide to the Reactions plugin is available here. A list of available parameters can be found at the Gigya developers site showReactionBarUI documentation page.
hook_gigya_shareui_alter
  • &$shareui_params
This hook is called before adding the socialize.showShareUI configuration parameters to the Javascript settings.
A list of available parameters can be found at the method's API page. Note this is used for “action sharing”, defined by Drupal’s rules mechanism.
hook_gigya_comments_alter
  • &$comments_params
This hook is called before adding the socialize.showCommentsUI configuration parameters to the Javascript settings. Developer's guide to the Comments plugin is available here. A list of available parameters can be found at the showCommentsUI API page.
hook_gigya_gm_block_alter
  • &$js_array
  • $js_block_name

This hook alters params of a specific GM block.

hook_gigya_gm_notifications_alter
  • &$notification_settings

Alter the notifications plugin parameters. The following example would prevent the notification popup from closing automatically: $notification_settings['closeTimeout'] = 0;. See relevant keys. $notification_settings is the array that would passed to the notification plugin.

Code Sample

The following is a PHP code sample that illustrate a basic use of hooks to alter parameters sent to the Game mechanics plugin before they are loaded.

/**
 * @file
 * Test module for GM - add a hook to support passing parameters to GM plugins.
 * Embed this code into your module to apply it to the Gigya module.
 */

//Use the hook_gigya_gm_block_alter hook to manipulate the GM blocks parameters.
//where hook is a placeholder for your module name.
function hook_gigya_gm_block_alter(&$js_array, $js_block_name) {
   // Apply the settings only to the specific 'test' block
   if ($js_block_name == 'test') {
    //Change the 'width' parameter of the 'Achievements' plugin
    $js_array['achievementsParams']['width'] = 500;
    ////Change the 'width' parameter of the 'Challenge status' plugin
    $js_array['challengeStatusParams']['width'] = 500;
    //And so on...
    $js_array['leaderboardParams']['width'] = 500;
    $js_array['userStatusParams']['width'] = 500;
   }
 }

//The hook_gigya_gm_notifications_alter hook is used to manipulate the notifications plugin
function hook_gigya_gm_notifications_alter(&$notification_settings) {
     $notification_settings['closeTimeout'] = 60000;
  }
 
//Use hook_gigya_tokens_alter to substitute content of a token
function hook_gigya_tokens_alter(&$replacements, $tokens, $gigya_user_info) {  
    $replacements['[gigya:test4]'] = $gigya_user_info['data']['test4'];
}

 

Save