function mb_comment_form_alter in More Buttons 7
Implements hook_form_alter().
File
- mb_comment/
mb_comment.module, line 64 - Provides a Cancel button for comments.
Code
function mb_comment_form_alter(&$form, &$form_state, $form_id) {
$module = 'mb_comment';
if ($form['#id']) {
if ($form['#id'] == 'comment-form') {
$node = $form['#node'];
if (arg(0) == 'comment') {
$default_values = mb_default_values();
$mb_content_values = mb_get_values('mb');
$destination = drupal_get_destination();
$settings = array();
$settings['cancel'] = variable_get($module . '_cancel_' . $node->type, 0);
if (!preg_match('/comment\\/reply/', url($_SERVER["HTTP_REFERER"]))) {
$form['comment_referer'] = array(
'#type' => 'value',
'#value' => url($_SERVER["HTTP_REFERER"]),
);
}
$form_state['cache'] = TRUE;
// Define the "Cancel" form element.
if ($settings['cancel'] > 0) {
if ($settings['cancel'] == 1) {
$weight_cancel = $form['actions']['submit']['#weight'] - 1;
}
elseif ($settings['cancel'] == 2) {
$weight_cancel = 16;
}
$form['actions']['cancel'] = array(
'#type' => 'submit',
'#value' => isset($mb_comment_values['cancel']) ? t('@cancel-value', array(
'@cancel-value' => t($mb_comment_values['cancel']),
)) : t($default_values['cancel']),
'#weight' => 30,
'#validate' => array(
'mb_comment_cancel_validate',
),
);
}
}
}
}
switch ($form_id) {
case 'node_type_delete_confirm':
// Delete MB Comment content type system variables
// if content types will be deleted.
$form['#submit'][] = 'mb_comment_delete_confirm_submit';
break;
case 'node_type_form':
// Provide the prepared additional MB Comment button settings.
// Check the specific case add content type form.
if (empty($form['#node_type']->type)) {
// Add content type.
$type = 'mb_comment_type_dummy';
}
else {
// Edit an content type.
$type = $form['#node_type']->type;
}
// It makes no sense to use the MB Comment module with the content type panel.
if ($type == 'panel') {
return;
}
// The additional button settings.
$form['comment_buttons'] = array(
'#type' => 'fieldset',
'#title' => t('Button settings - comments'),
'#group' => 'additional_settings',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 5,
'#attached' => array(
'js' => array(
drupal_get_path('module', $module) . '/' . $module . '_node_form.js',
),
),
);
// Provide "Cancel" button settings.
$form['comment_buttons'][$module . '_cancel'] = array(
'#type' => 'select',
'#title' => t('Cancel button'),
'#description' => t('Please select using the button or its position.'),
'#options' => mb_cancel_button_positions(),
'#default_value' => variable_get($module . '_cancel_' . $type, 0),
);
break;
}
}