function facebook_comments_form_node_form_alter in Facebook Comments Social Plugin 7
Implements hook_form_alter().
Add the Facebook commenting options for a node.
File
- ./
facebook_comments.module, line 279 - Facebook Comments Social Plugin module file.
Code
function facebook_comments_form_node_form_alter(&$form, $form_state) {
// Load the default values.
$node = $form['#node'];
// If this is a preview then get the values from the form, not the db.
if (isset($form_state['values']['op']) && $form_state['values']['op'] == t('Preview')) {
$defaults = new StdClass();
$defaults->enabled = $form_state['values']['facebook_comments_enabled'];
$defaults->amount = $form_state['values']['facebook_comments_amount'];
}
elseif (isset($node->nid) && $node->nid > 0) {
// Load the values from the db if we are viewing an existing node.
$defaults = db_select('facebook_comments', 'f')
->fields('f', array(
'enabled',
'amount',
))
->condition('f.nid', $node->nid, '=')
->execute()
->fetchObject();
// If the node existed before we installed facebook_comments add, default values.
if (!$defaults) {
$defaulttypes = variable_get('facebook_comments_types', array());
$defaults = new StdClass();
$defaults->enabled = FALSE;
$defaults->amount = 15;
}
}
else {
// Init standard values.
$defaulttypes = variable_get('facebook_comments_types', array());
$defaults = new StdClass();
$defaults->enabled = !empty($defaulttypes[$node->type]) ? 1 : 0;
$defaults->amount = 15;
}
$form['facebook_comments'] = array(
'#type' => 'fieldset',
'#title' => t('Facebook comments'),
'#group' => 'additional_settings',
'#access' => user_access('moderate facebook comments'),
'#attributes' => array(
'class' => array(
'edit-facebook-comments',
),
),
'#attached' => array(
'js' => array(
'vertical-tabs' => drupal_get_path('module', 'facebook_comments') . "/facebook_comments_vertical_tabs.js",
),
),
);
// Enable or disable Facebook comments for this node.
$form['facebook_comments']['facebook_comments_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Facebook comments'),
'#default_value' => $defaults->enabled,
);
// Amount of comments.
$form['facebook_comments']['facebook_comments_amount'] = array(
'#type' => 'select',
'#title' => t('Amount of comments to display'),
'#options' => array(
1 => 1,
2 => 2,
3 => 3,
5 => 5,
7 => 7,
10 => 10,
15 => 15,
20 => 20,
30 => 30,
),
'#default_value' => $defaults->amount,
);
}