function submitted_by_form_alter in Submitted By 6
Implementation of hook_form_alter().
Add the pattern field to the node edit form for comments.
File
- ./
submitted_by.module, line 27 - Take over the "Submitted by" theme function to allow different content types to have different strings.
Code
function submitted_by_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'node_type_form':
if (isset($form['comment'])) {
$form['comment']['comment']['#weight'] = -5;
$type = isset($form['#node_type']->type) ? $form['#node_type']->type : 'default';
$default = variable_get('submitted_by_comment_' . $type, NULL);
$form['comment']['appearance'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => empty($default),
'#title' => t('"Submitted by" Appearance'),
);
$form['comment']['appearance']['#weight'] = -1;
$form['comment']['appearance']['submitted_by']['submitted_by_comment'] = array(
'#type' => 'textfield',
'#maxlength' => 255,
'#title' => t("'Submitted by...' text"),
'#default_value' => $default,
'#description' => t("When a comment is displayed, text in this box will be used to override the normal attribution and date-posted text."),
);
if ($def_default = variable_get('submitted_by_comment_default', NULL)) {
$form['comment']['appearance']['submitted_by']['submitted_by_comment']['#description'] .= ' ' . t('The system default value is "%deflt."', array(
'%deflt' => $def_default,
));
}
$form['comment']['appearance']['submitted_by']['help'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Replacement tokens'),
'#description' => t("The following tokens can be used in the Submitted By... text. They will be replaced with the appropriate values."),
);
$form['comment']['appearance']['submitted_by']['help']['tokens'] = array(
'#value' => theme('token_help', 'comment'),
);
}
break;
case 'node_configure':
// Admin > Content > Post settings.
// Would this be better in system_theme_settings? ['node_info'], system_theme_settings_submit.
$node_default = variable_get('submitted_by_default', NULL);
$form['appearance'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => empty($node_default),
'#title' => t('"Submitted by" Appearance'),
);
$form['appearance']['submitted_by']['#weight'] = -1;
// Note: node module will add "_type" to the variable name.
$form['appearance']['submitted_by']['submitted_by_default'] = array(
'#type' => 'textfield',
'#maxlength' => 255,
'#title' => t("Node 'Submitted by...' text"),
'#default_value' => $node_default,
'#description' => t("When a node is displayed, text in this box will be used to override the normal attribution and date-posted text."),
);
$form['appearance']['submitted_by']['help'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Replacement tokens'),
'#description' => t("The following tokens can be used in the Submitted By... text. They will be replaced with the appropriate values."),
);
$form['appearance']['submitted_by']['help']['tokens'] = array(
'#value' => theme('token_help', 'node'),
);
if (module_exists('comment')) {
$com_default = variable_get('submitted_by_comment_default', NULL);
$form['comment']['appearance'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => empty($com_default),
'#title' => t('Comment "Submitted by" Appearance'),
'#weight' => -1,
);
$form['comment']['appearance']['submitted_by']['submitted_by_comment_default'] = array(
'#type' => 'textfield',
'#maxlength' => 255,
'#title' => t("'Submitted by...' text"),
'#default_value' => $com_default,
'#description' => t("When a comment is displayed, text in this box will be used to override the normal attribution and date-posted text."),
);
$form['comment']['appearance']['submitted_by']['help'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Replacement tokens'),
'#description' => t("The following tokens can be used in the Submitted By... text. They will be replaced with the appropriate values."),
);
$form['comment']['appearance']['submitted_by']['help']['tokens'] = array(
'#value' => theme('token_help', 'comment'),
);
$form['buttons']['#weight'] = 99;
// drupal_set_message(show_array($form));
break;
}
}
}