Commit 5a89fef9 authored by Dries's avatar Dries

- Patch #275368 by michaelfavia, sun, mattconnolly: allow disabling comment...

- Patch #275368 by michaelfavia, sun, mattconnolly: allow disabling comment preview + unify with node preview settings.
parent f0a8150b
......@@ -174,6 +174,26 @@ function comment_update_7008() {
db_add_index('comment', 'comment_nid_language', array('nid', 'language'));
}
/**
* Update preview setting variable to use new constants
*/
function comment_update_7009() {
foreach (node_type_get_types() as $type => $object) {
// There were only two comment modes in the past:
// - 1 was 'required' previously, convert into DRUPAL_REQUIRED (2).
// - 0 was 'optional' previously, convert into DRUPAL_OPTIONAL (1).
$original_preview = variable_get('comment_preview_' . $type, 1);
if ($original_preview) {
$preview = DRUPAL_REQUIRED;
}
else {
$preview = DRUPAL_OPTIONAL;
}
variable_set('comment_preview_' . $type, $preview);
}
return array();
}
/**
* @} End of "defgroup updates-6.x-to-7.x"
* The next series of updates should start at 8000.
......
......@@ -70,16 +70,6 @@
*/
define('COMMENT_NODE_OPEN', 2);
/**
* Comment preview is optional.
*/
define('COMMENT_PREVIEW_OPTIONAL', 0);
/**
* Comment preview is required.
*/
define('COMMENT_PREVIEW_REQUIRED', 1);
/**
* Implement hook_help().
*/
......@@ -1010,9 +1000,14 @@ function comment_form_node_type_form_alter(&$form, $form_state) {
'#default_value' => variable_get('comment_form_location_' . $form['#node_type']->type, COMMENT_FORM_BELOW),
);
$form['comment']['comment_preview'] = array(
'#type' => 'checkbox',
'#title' => t('Require preview'),
'#default_value' => variable_get('comment_preview_' . $form['#node_type']->type, COMMENT_PREVIEW_OPTIONAL),
'#type' => 'radios',
'#title' => t('Preview comment'),
'#default_value' => variable_get('comment_preview_' . $form['#node_type']->type, DRUPAL_OPTIONAL),
'#options' => array(
DRUPAL_DISABLED => t('Disabled'),
DRUPAL_OPTIONAL => t('Optional'),
DRUPAL_REQUIRED => t('Required'),
),
);
}
}
......@@ -1874,16 +1869,16 @@ function comment_form($form, &$form_state, $comment) {
// already previewing the submission. However, if there are form errors,
// we hide the save button no matter what, so that optional form elements
// (e.g., captchas) can be updated.
if (!form_get_errors() && ((variable_get('comment_preview_' . $node->type, COMMENT_PREVIEW_OPTIONAL) == COMMENT_PREVIEW_OPTIONAL) || ($op == t('Preview')) || ($op == t('Save')))) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 19,
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#access' => variable_get('comment_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_REQUIRED || (!form_get_errors() && isset($form_state['comment_preview'])),
'#weight' => 19,
);
$form['preview'] = array(
'#type' => 'submit',
'#value' => t('Preview'),
'#access' => (variable_get('comment_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_DISABLED),
'#weight' => 20,
'#submit' => array('comment_form_build_preview'),
);
......
This diff is collapsed.
......@@ -160,7 +160,7 @@ function node_type_form($form, &$form_state, $type = NULL) {
DRUPAL_OPTIONAL => t('Optional'),
DRUPAL_REQUIRED => t('Required'),
),
);
);
$form['submission']['help'] = array(
'#type' => 'textarea',
'#title' => t('Explanation or submission guidelines'),
......
......@@ -263,13 +263,13 @@ function node_form($form, &$form_state, $node) {
$form['buttons']['#weight'] = 100;
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#access' => variable_get('node_preview_' . $node->type, 1) != DRUPAL_REQUIRED || (!form_get_errors() && isset($form_state['node_preview'])),
'#access' => variable_get('node_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_REQUIRED || (!form_get_errors() && isset($form_state['node_preview'])),
'#value' => t('Save'),
'#weight' => 5,
'#submit' => array('node_form_submit'),
);
$form['buttons']['preview'] = array(
'#access' => variable_get('node_preview_' . $node->type, 1) != DRUPAL_DISABLED,
'#access' => variable_get('node_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_DISABLED,
'#type' => 'submit',
'#value' => t('Preview'),
'#weight' => 10,
......
......@@ -468,7 +468,7 @@ class SearchCommentTestCase extends DrupalWebTestCase {
function testSearchResultsComment() {
$comment_body = $this->randomName(5);
variable_set('comment_preview_article', COMMENT_PREVIEW_OPTIONAL);
variable_set('comment_preview_article', DRUPAL_OPTIONAL);
// Enable check_plain() for 'Filtered HTML' text format.
$edit = array(
'filters[filter_html_escape][status]' => 1,
......
......@@ -525,7 +525,7 @@ class UserCancelTestCase extends DrupalWebTestCase {
// Create comment.
module_load_include('test', 'comment');
$comment = CommentHelperCase::postComment($node, '', $this->randomName(32), FALSE, TRUE);
$comment = CommentHelperCase::postComment($node, $this->randomName(32), '', TRUE);
$this->assertTrue(comment_load($comment->id), t('Comment found.'));
// Create a node with two revisions, the initial one belonging to the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment