5

How can I change "Default comments per page" array to my own. What hook I need to use, if it needed? hook_form_FORM_ID_alter(&$form, &$form_state) with FORM_ID = node_type_form

$form doesn't contain this value

4

Drupal pulls the number of comments per page from variable_get('comment_default_per_page' . $node->type). Its default is 50. To change this go to content type X -> edit, then save.

To change the 50 to something else, you can create you own custom module and have this code

function example_form_alter(&$form, &$form_state, $form_id) {
    if ($form_id == 'node_type_form' && isset($form['comment'])) {
        $form['comment']['comment_default_per_page']['#default_value'] = 70;
    }   
}

Comment setting for a node content type

If you want to change it somewhere else, then I recommend calling variable_set('comment_default_per_page' . $node->type, 'MYVALUE'). See below where it is hard-coded inside comment.module & comment_form:

$form['comment']['comment_default_per_page'] = array(
  '#type' => 'select',
  '#title' => t('Default comments per page'),
  '#default_value' => variable_get('comment_default_per_page_'. $form['#node_type']->type, 50),
  '#options' => _comment_per_page(),
  '#description' => t('Default number of comments for each page: more comments are distributed in several pages.'),
);


function _comment_get_display_setting($setting, $node) {
  global $user;

  if (isset($_GET[$setting])) {
    $value = $_GET[$setting];
  }
  else {
    // get the setting's site default
    switch ($setting) {
      case 'mode':
        $default = variable_get('comment_default_mode_'. $node->type, COMMENT_MODE_THREADED_EXPANDED);
        break;
      case 'sort':
        $default = variable_get('comment_default_order_'. $node->type, COMMENT_ORDER_NEWEST_FIRST);
        break;
      case 'comments_per_page':
        $default = variable_get('comment_default_per_page_'. $node->type, 50);
    }
...

and inside comment_render($node, $cid = 0) {

$comments_per_page = _comment_get_display_setting('comments_per_page', $node);
1
  • Thanks a lot.. it's working fine for D7,, but you forgot to add underscore before the content type.. the correct is: variable_set('comment_default_per_page_' . $node->type, 'MYVALUE') Apr 29 '13 at 12:47
0

The default comments per page is stored and changed on the content type itself. In D6 it was stored using variable_set() but I'm not sure if this is the case for D7.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.