janrain_capture_mapping.module in Janrain Registration 7
This module implements a data mapping UI for Janrain Capture
File
janrain_capture_mapping/janrain_capture_mapping.moduleView source
<?php
/**
* @file
* This module implements a data mapping UI for Janrain Capture
*/
/**
* Implements hook_menu().
*/
function janrain_capture_mapping_menu() {
$items['admin/config/people/janrain_capture/mapping'] = array(
'title' => 'Field Mapping',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'janrain_capture_settings_mapping',
),
'access arguments' => array(
'administer site configuration',
),
'type' => MENU_LOCAL_TASK,
'weight' => -8,
'file' => 'janrain_capture_mapping.admin.inc',
);
$items["admin/config/people/janrain_capture/fields"] = array(
'title' => 'Manage fields',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'janrain_capture_settings_fields',
),
'access arguments' => array(
'administer site configuration',
),
'type' => MENU_LOCAL_TASK,
'weight' => -7,
'file' => 'janrain_capture_mapping.admin.inc',
);
$items['admin/config/people/janrain_capture/fields/reset'] = array(
'title' => 'Reset to defaults',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'janrain_capture_settings_fields_reset',
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'janrain_capture_mapping.admin.inc',
);
$items['admin/config/people/janrain_capture/fields/edit'] = array(
'title' => 'Edit field',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'janrain_capture_settings_fields_edit',
),
'access arguments' => array(
'administer site configuration',
),
'type' => MENU_CALLBACK,
'file' => 'janrain_capture_mapping.admin.inc',
);
$items['admin/config/people/janrain_capture/fields/delete'] = array(
'title' => 'Delete field',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'janrain_capture_settings_fields_delete',
),
'access arguments' => array(
'administer site configuration',
),
'type' => MENU_CALLBACK,
'file' => 'janrain_capture_mapping.admin.inc',
);
return $items;
}
/**
* Implementation of hook_theme().
*/
function janrain_capture_mapping_theme() {
return array(
'janrain_capture_settings_mapping' => array(
'render element' => 'form',
'file' => 'janrain_capture_mapping.admin.inc',
),
'janrain_capture_settings_fields' => array(
'render element' => 'form',
'file' => 'janrain_capture_mapping.admin.inc',
),
);
}
/**
* Implements hook_janrain_capture_profile_sync().
*/
function janrain_capture_mapping_janrain_capture_profile_sync($account, $profile) {
$map = variable_get('janrain_capture_mapping_map', array());
$wrapper = entity_metadata_wrapper('user', $account);
$capture_fields = db_query("SELECT fid, path FROM {janrain_capture_mapping_field}")
->fetchAllKeyed();
foreach ($map as $mapping) {
try {
$value = $profile[$capture_fields[$mapping['fid']]];
if (isset($mapping['column']) && $mapping['column'] != 'value') {
$value = array(
$mapping['column'] => $profile[$capture_fields[$mapping['fid']]],
);
}
$wrapper->{$mapping['field']} = $value;
} catch (EntityMetadataWrapperException $e) {
watchdog('Capture Mapping', 'Attempt to map attr @attr to field @field failed', array(
'@attr' => $profile[$capture_fields[$mapping['fid']]],
'@field' => $mapping['field'],
));
}
}
}
/********************************* Helper Functions ************************************************/
/**
* Inserts the default capture profile fields into the database, ready to be mapped
* to user properties and fields.
*/
function _janrain_capture_mapping_insert_defaults() {
$fields = array(
'uuid' => array(
'name' => 'UUID',
),
'email' => array(
'name' => 'Email',
),
'givenName' => array(
'name' => 'First Name',
),
'familyName' => array(
'name' => 'Last Name',
),
'displayName' => array(
'name' => 'Display Name',
),
'gender' => array(
'name' => 'Gender',
),
'birthday' => array(
'name' => 'Birthday',
),
);
foreach ($fields as $attr => $field) {
$fid = db_insert('janrain_capture_mapping_field')
->fields(array(
'title' => $field['name'],
'path' => $attr,
))
->execute();
$fields[$attr]['fid'] = $fid;
}
}
Functions
Name | Description |
---|---|
janrain_capture_mapping_janrain_capture_profile_sync | Implements hook_janrain_capture_profile_sync(). |
janrain_capture_mapping_menu | Implements hook_menu(). |
janrain_capture_mapping_theme | Implementation of hook_theme(). |
_janrain_capture_mapping_insert_defaults | Inserts the default capture profile fields into the database, ready to be mapped to user properties and fields. |