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() { ...@@ -174,6 +174,26 @@ function comment_update_7008() {
db_add_index('comment', 'comment_nid_language', array('nid', 'language')); 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" * @} End of "defgroup updates-6.x-to-7.x"
* The next series of updates should start at 8000. * The next series of updates should start at 8000.
......
...@@ -70,16 +70,6 @@ ...@@ -70,16 +70,6 @@
*/ */
define('COMMENT_NODE_OPEN', 2); 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(). * Implement hook_help().
*/ */
...@@ -1010,9 +1000,14 @@ function comment_form_node_type_form_alter(&$form, $form_state) { ...@@ -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), '#default_value' => variable_get('comment_form_location_' . $form['#node_type']->type, COMMENT_FORM_BELOW),
); );
$form['comment']['comment_preview'] = array( $form['comment']['comment_preview'] = array(
'#type' => 'checkbox', '#type' => 'radios',
'#title' => t('Require preview'), '#title' => t('Preview comment'),
'#default_value' => variable_get('comment_preview_' . $form['#node_type']->type, COMMENT_PREVIEW_OPTIONAL), '#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) { ...@@ -1874,16 +1869,16 @@ function comment_form($form, &$form_state, $comment) {
// already previewing the submission. However, if there are form errors, // already previewing the submission. However, if there are form errors,
// we hide the save button no matter what, so that optional form elements // we hide the save button no matter what, so that optional form elements
// (e.g., captchas) can be updated. // (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(
$form['submit'] = array( '#type' => 'submit',
'#type' => 'submit', '#value' => t('Save'),
'#value' => t('Save'), '#access' => variable_get('comment_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_REQUIRED || (!form_get_errors() && isset($form_state['comment_preview'])),
'#weight' => 19, '#weight' => 19,
); );
}
$form['preview'] = array( $form['preview'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Preview'), '#value' => t('Preview'),
'#access' => (variable_get('comment_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_DISABLED),
'#weight' => 20, '#weight' => 20,
'#submit' => array('comment_form_build_preview'), '#submit' => array('comment_form_build_preview'),
); );
......
This diff is collapsed.
...@@ -160,7 +160,7 @@ function node_type_form($form, &$form_state, $type = NULL) { ...@@ -160,7 +160,7 @@ function node_type_form($form, &$form_state, $type = NULL) {
DRUPAL_OPTIONAL => t('Optional'), DRUPAL_OPTIONAL => t('Optional'),
DRUPAL_REQUIRED => t('Required'), DRUPAL_REQUIRED => t('Required'),
), ),
); );
$form['submission']['help'] = array( $form['submission']['help'] = array(
'#type' => 'textarea', '#type' => 'textarea',
'#title' => t('Explanation or submission guidelines'), '#title' => t('Explanation or submission guidelines'),
......
...@@ -263,13 +263,13 @@ function node_form($form, &$form_state, $node) { ...@@ -263,13 +263,13 @@ function node_form($form, &$form_state, $node) {
$form['buttons']['#weight'] = 100; $form['buttons']['#weight'] = 100;
$form['buttons']['submit'] = array( $form['buttons']['submit'] = array(
'#type' => 'submit', '#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'), '#value' => t('Save'),
'#weight' => 5, '#weight' => 5,
'#submit' => array('node_form_submit'), '#submit' => array('node_form_submit'),
); );
$form['buttons']['preview'] = array( $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', '#type' => 'submit',
'#value' => t('Preview'), '#value' => t('Preview'),
'#weight' => 10, '#weight' => 10,
......
...@@ -468,7 +468,7 @@ class SearchCommentTestCase extends DrupalWebTestCase { ...@@ -468,7 +468,7 @@ class SearchCommentTestCase extends DrupalWebTestCase {
function testSearchResultsComment() { function testSearchResultsComment() {
$comment_body = $this->randomName(5); $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. // Enable check_plain() for 'Filtered HTML' text format.
$edit = array( $edit = array(
'filters[filter_html_escape][status]' => 1, 'filters[filter_html_escape][status]' => 1,
......
...@@ -525,7 +525,7 @@ class UserCancelTestCase extends DrupalWebTestCase { ...@@ -525,7 +525,7 @@ class UserCancelTestCase extends DrupalWebTestCase {
// Create comment. // Create comment.
module_load_include('test', '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.')); $this->assertTrue(comment_load($comment->id), t('Comment found.'));
// Create a node with two revisions, the initial one belonging to the // 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