In node.module a function called node_configure() sets the number of teasers I can view on a page:

'#options' =>  drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25))

I want to view 300.

I don't want to use views.

I don't want to just add '300' to the array.

I thought the solution would be to tweak the form in template.php:

function phptemplate_node_configure($form){
$form['default_nodes_main']['#options'] = drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 300));
return drupal_render($form);
}

But it doesn't work. If I choose 300 on the form, I get an error.

So how do you configure the number of teasers without hacking core?

Comments

dave reid’s picture

Use views?

MauMau’s picture

Status: Active » Fixed

I use views very often and I like it very much.

This project, however, will have to use node.module to display teasers.

My solution was to make a new module:


<?php
// override_node_configure.module - show more teasers


function override_node_configure_menu($cache) {

    $items[] = array(
      'path' => 'admin/content/node-settings',
      'title' => t('Post settings'),
      'description' => t('Control posting behavior, such as teaser length, requiring previews before posting, and the number of posts on the front page.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array('override_node_configure'),
      'access' => user_access('administer nodes')
    );
  
   return $items;

}


/**
 * Menu callback; presents general node configuration options.
 */
function override_node_configure() {
// Only show rebuild button if there is 0 or more than 2 rows in node_access table, or if there are modules that implement node_grant.
  if (db_result(db_query('SELECT COUNT(*) FROM {node_access}')) != 1 || count(module_implements('node_grants')) > 0) {
    $status = '<p>'. t('If the site is experiencing problems with permissions to content, you may have to rebuild the permissions cache. Possible causes for permission problems are disabling modules or configuration changes to permissions. Rebuilding will remove all privileges to posts, and replace them with permissions based on the current modules and settings.') .'</p>';
    $status .= '<p>'. t('Rebuilding may take some time if there is a lot of content or complex permission settings. After rebuilding has completed posts will automatically use the new permissions.') .'</p>';

    $form['access'] = array('#type' => 'fieldset', '#title' => t('Node access status'));
    $form['access']['status'] = array('#value' => $status);
    $form['access']['rebuild'] = array('#type' => 'submit', '#value' => t('Rebuild permissions'));
  }

  $form['default_nodes_main'] = array(
    '#type' => 'select', '#title' => t('Number of posts on main page'), '#default_value' => variable_get('default_nodes_main', 10),
    '#options' =>  drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 300, 400)),
    '#description' => t('The default maximum number of posts to display per page on overview pages such as the main page.')
  );
  $form['teaser_length'] = array(
    '#type' => 'select', '#title' => t('Length of trimmed posts'), '#default_value' => variable_get('teaser_length', 600),
    '#options' => array(0 => t('Unlimited'), 200 => t('200 characters'), 400 => t('400 characters'), 600 => t('600 characters'),
      800 => t('800 characters'), 1000 => t('1000 characters'), 1200 => t('1200 characters'), 1400 => t('1400 characters'),
      1600 => t('1600 characters'), 1800 => t('1800 characters'), 2000 => t('2000 characters')),
    '#description' => t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited'. Note that this setting will only affect new or updated content and will not affect existing teasers.")
  );

  $form['node_preview'] = array(
    '#type' => 'radios', '#title' => t('Preview post'), '#default_value' => variable_get('node_preview', 0),
    '#options' => array(t('Optional'), t('Required')), '#description' => t('Must users preview posts before submitting?')
  );

  return system_settings_form($form);
}


?>

It looks like it's working.

Gurpartap Singh’s picture

You could simply add the 300 option using hook_form_alter() and it wouldn't produce the validation error as you might have encountered with the template.php hack.

Anonymous’s picture

The hook_form_alter is the correct way to do this.

function foo_form_alter($form_id, &$form) {
  $func = "_foo_alter_$form_id";
  if (function_exists($func)) {
    $func($form_id, $form);
  }
}

function _foo_alter_node_configure($form_id, &$form) {
  if (isset($form['default_nodes_main'])) {
    $form['default_nodes_main']['#options'] = drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 300, 400));
  }
}
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.