function _fb_registration_extract_fb_fields in Drupal for Facebook 6.3
Same name and namespace in other branches
- 7.3 contrib/fb_registration.module \_fb_registration_extract_fb_fields()
1 call to _fb_registration_extract_fb_fields()
- fb_registration_form_alter in contrib/
fb_registration.module - Implements hook_form_alter().
File
- contrib/
fb_registration.module, line 137 - http://developers.facebook.com/docs/user_registration
Code
function _fb_registration_extract_fb_fields(&$fb_fields, &$form) {
foreach (element_children($form) as $key) {
$field = NULL;
if (isset($form[$key]['#fb_registration_field'])) {
if (is_string($form[$key]['#fb_registration_field'])) {
// This field is a "built in field".
$field = array(
'name' => $form[$key]['#fb_registration_field'],
);
}
elseif (is_array($form[$key]['#fb_registration_field'])) {
$field = $form[$key]['#fb_registration_field'];
}
}
else {
// #fb_registration_field not specified, fallback to the following
// code, which translates some drupal form elements into facebook
// fields.
if (!isset($form[$key]['#type'])) {
_fb_registration_extract_fb_fields($fb_fields, $form[$key]);
}
elseif ($form[$key]['#type'] == 'fieldset') {
_fb_registration_extract_fb_fields($fb_fields, $form[$key]);
$form[$key] = NULL;
// So the (now empty?) fieldset will not be rendered.
}
elseif ($form[$key]['#type'] == 'submit') {
// We have to use the register button provided by facebook.
$form[$key] = NULL;
}
elseif ($form[$key]['#type'] == 'textfield') {
$field = array(
'name' => $key,
'type' => 'text',
'description' => $form[$key]['#title'],
);
}
elseif ($form[$key]['#type'] == 'textarea') {
// Facebook does not offer multi-line text area. Use single line instead.
$field = array(
'name' => $key,
'type' => 'text',
'description' => $form[$key]['#title'],
);
}
elseif ($form[$key]['#type'] == 'checkbox') {
$field = array(
'name' => $key,
'type' => 'checkbox',
'description' => $form[$key]['#title'],
'default' => isset($form[$key]['#default_value']) ? $form[$key]['#default_value'] : NULL,
);
}
elseif ($form[$key]['#type'] == 'select') {
$field = array(
'name' => $key,
'type' => 'select',
'description' => $form[$key]['#title'],
'options' => $form[$key]['#options'],
'default' => $form[$key]['#default_value'],
);
}
// @TODO do something intelligent with unknown element types.
}
if (count($field)) {
// Use the facebook field...
$fb_fields[] = $field;
// and not the drupal field.
$form[$key] = NULL;
}
}
}