function fb_canvas_form_alter in Drupal for Facebook 5
Same name and namespace in other branches
- 5.2 fb_canvas.module \fb_canvas_form_alter()
- 6.3 fb_canvas.module \fb_canvas_form_alter()
- 6.2 fb_canvas.module \fb_canvas_form_alter()
- 7.3 fb_canvas.module \fb_canvas_form_alter()
Implementation of hook_form_alter.
File
- ./
fb_canvas.module, line 103 - This module provides some app-specific navigation to facebook apps. This is fairly experimental material. May change a lot in near future.
Code
function fb_canvas_form_alter($form_id, &$form) {
// Add our settings to the fb_app edit form.
if (is_array($form['fb_app_data'])) {
$node = $form['#node'];
$fb_app_data = fb_app_get_data($node->fb_app);
$fb_canvas_data = $fb_app_data['fb_canvas'];
// defaults
if (!$fb_canvas_data) {
$fb_canvas_data = array();
}
$fb_canvas_data = array_merge(array(
'theme_fbml' => 'fb_fbml',
'theme_iframe' => 0,
), $fb_canvas_data);
$form['fb_app_data']['fb_canvas'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Facebook canvas page settings'),
'#description' => t('Allows application-specific front page and navigation links.'),
);
$form['fb_app_data']['fb_canvas']['front_anonymous'] = array(
'#type' => 'textfield',
'#title' => t('Front page when user is not logged in'),
'#description' => t('Leave blank to use the site-wide front page.'),
'#default_value' => $fb_canvas_data['front_anonymous'],
);
$form['fb_app_data']['fb_canvas']['front_loggedin'] = array(
'#type' => 'textfield',
'#title' => t('Front page when user is logged in, but has not added the app.'),
'#description' => t('Leave blank to use the site-wide front page.'),
'#default_value' => $fb_canvas_data['front_loggedin'],
);
$form['fb_app_data']['fb_canvas']['front_added'] = array(
'#type' => 'textfield',
'#title' => t('Front page when user has added this application.'),
'#description' => t('Leave blank to use the site-wide front page.'),
'#default_value' => $fb_canvas_data['front_added'],
);
// Allow primary links to be different on facebook versus the rest of the
// site. Code from menu_configure() in menu.module.
$root_menus = menu_get_root_menus();
$primary_options = $root_menus;
$primary_options[0] = t('<use sitewide setting>');
$secondary_options = $root_menus;
$secondary_options[0] = t('<use sitewide setting>');
$form['fb_app_data']['fb_canvas']['primary_links'] = array(
'#type' => 'select',
'#title' => t('Menu containing primary links'),
'#description' => t('Your application can have primary links different from those used elsewhere on your site.'),
'#default_value' => $fb_canvas_data['primary_links'],
'#options' => $primary_options,
);
$form['fb_app_data']['fb_canvas']['secondary_links'] = array(
'#type' => 'select',
'#title' => t('Menu containing secondary links'),
'#default_value' => $fb_canvas_data['secondary_links'],
'#options' => $secondary_options,
'#description' => t('If you select the same menu as primary links then secondary links will display the appropriate second level of your navigation hierarchy.'),
);
// Override themes
$themes = system_theme_data();
ksort($themes);
$theme_options[0] = t('System default');
foreach ($themes as $theme) {
$theme_options[$theme->name] = $theme->name;
}
$form['fb_app_data']['fb_canvas']['theme_fbml'] = array(
'#type' => 'select',
'#title' => t('Theme for FBML pages'),
'#description' => t('Choose only a theme that is FBML-aware.'),
'#options' => $theme_options,
'#required' => TRUE,
'#default_value' => $fb_canvas_data['theme_fbml'],
);
$form['fb_app_data']['fb_canvas']['theme_iframe'] = array(
'#type' => 'select',
'#title' => t('Theme for iframe pages'),
'#description' => t('Choose only a facebook-aware theme'),
'#options' => $theme_options,
'#required' => TRUE,
'#default_value' => $fb_canvas_data['theme_iframe'],
);
}
global $fb, $fb_app;
// We will send all form submission directly to us, not via
// apps.facebook.com/whatever.
if (fb_canvas_is_fbml()) {
// We're in a facebook callback
// Can't use 'fb_handling_form' because facebook strips it.
$form['_fb_handling_form'] = array(
'#value' => TRUE,
'#type' => 'hidden',
);
// We need to make sure the action goes to our domain and not apps.facebook.com
if ($form['#action'] == '') {
$form['#action'] = $_GET['q'];
}
$form['#action'] = _fb_canvas_make_form_action_local($form['#action']);
// Let's hope no subsequent hook_form_alters mess with #action.
}
else {
if (fb_canvas_is_iframe()) {
//dpm($form, 'fb_canvas_form_alter');
}
}
}