? patch.txt Index: excerpt.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/excerpt/excerpt.module,v retrieving revision 1.12 diff -u -p -r1.12 excerpt.module --- excerpt.module 27 Mar 2008 11:54:15 -0000 1.12 +++ excerpt.module 8 Jun 2008 18:20:05 -0000 @@ -1,11 +1,25 @@ type, 1)) { + if (variable_get('excerpt_'. $node->type, variable_get('excerpt_default', EXCERPT_DEFAULT))) { switch ($op) { case 'submit': // Due to the presence of the teaser field in the node form, @@ -23,15 +37,15 @@ function excerpt_nodeapi(&$node, $op, $a if (trim($node->teaser) == '' && $node->body != '') { $node->teaser = node_teaser($node->body, isset($node->format) ? $node->format : NULL); } + break; + + case 'view': // node.module just checks whether the length of the teaser is less // than the body length to decide whether a "read more" link is to be // shown. With excerpts however, teasers can be even longer than the // body field, which is why we need to overwrite that property with our // own condition. - return array('excerpt' => (bool)strcmp($node->teaser, $node->body)); - - case 'view': - $node->readmore = $node->excerpt; + $node->readmore = (bool)strcmp($node->teaser, $node->body); break; } } @@ -41,34 +55,59 @@ function excerpt_nodeapi(&$node, $op, $a * Implementation of hook_form_alter(). */ function excerpt_form_alter($form_id, &$form) { - if ($form_id == 'node_type_form' && isset($form['identity']['type'])) { - $form['workflow']['excerpt'] = array( - '#type' => 'fieldset', - '#title' => t('Excerpt'), - '#weight' => 0, - ); - $form['workflow']['excerpt']['excerpt'] = array( - '#type' => 'radios', - '#title' => t('Teaser'), - '#default_value' => variable_get('excerpt_'. $form['#node_type']->type, 1), - '#options' => array(t('Auto-generated'), t('Manual excerpt')), - '#description' => t('Choose whether the node teaser must be generated automatically or manually entered by the author.'), - ); - $form['workflow']['excerpt']['excerpt_wt'] = array( - '#type' => 'weight', - '#title' => t('Weight of Teaser field'), - '#default_value' => variable_get('excerpt_wt_'. $form['#node_type']->type, 0), - ); - } - else if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && variable_get('excerpt_'. $form['type']['#value'], 1)) { - $form['teaser'] = array( - '#type' => 'textarea', - '#title' => t('Teaser'), - '#default_value' => $form['#node']->teaser, - '#cols' => 60, - '#rows' => 6, - '#weight' => variable_get('excerpt_wt_'. $form['type']['#value'], 0), - '#description' => t('Enter an excerpt for this item. It will be shown on listing pages along with a read more link which leads to the full view. Leave empty to auto-generate one from the body.'), - ); +switch ($form['#id']) { + case 'node-configure': + $form['excerpt'] = array( + '#type' => 'fieldset', + '#title' => t('Excerpt'), + '#weight' => -1, + ); + $form['excerpt']['excerpt_size'] = array( + '#type' => 'select', + '#title' => t('Height of excerpt textarea'), + '#default_value' => variable_get('excerpt_size', EXCERPT_SIZE_MIN), + '#options' => drupal_map_assoc(range(EXCERPT_SIZE_MIN, EXCERPT_SIZE_MAX)), + '#description' => t('Number of teaser texarea rows.'), + ); + $form['excerpt']['excerpt_default'] = array( + '#type' => 'select', + '#title' => t('Default teasers'), + '#default_value' => variable_get('excerpt_default', EXCERPT_DEFAULT), + '#options' => array(t('Auto-generated'), t('Manual excerpt')), + '#description' => t('Choose whether teasers are generated automatically or can be entered manually by the author.'), + ); + break; + case 'node-type-form': + $form['workflow']['excerpt'] = array( + '#type' => 'fieldset', + '#title' => t('Excerpt'), + '#weight' => 0, + ); + $form['workflow']['excerpt']['excerpt'] = array( + '#type' => 'radios', + '#title' => t('Teaser'), + '#default_value' => variable_get('excerpt_'. $form['#node_type']->type, variable_get('excerpt_default', EXCERPT_DEFAULT)), + '#options' => array(t('Auto-generated'), t('Manual excerpt')), + '#description' => t('Choose whether the node teaser must be generated automatically or manually entered by the author.'), + ); + $form['workflow']['excerpt']['excerpt_wt'] = array( + '#type' => 'weight', + '#title' => t('Weight of Teaser field'), + '#default_value' => variable_get('excerpt_wt_'. $form['#node_type']->type, 0), + ); + break; + case 'node-form': + if (variable_get('excerpt_'. $form['#node']->type, variable_get('excerpt_default', EXCERPT_DEFAULT))) { + $form['teaser'] = array( + '#type' => 'textarea', + '#title' => t('Teaser'), + '#default_value' => $form['#node']->teaser, + '#cols' => 60, + '#rows' => variable_get('excerpt_size', EXCERPT_SIZE_MIN), + '#weight' => variable_get('excerpt_wt_'. $form['type']['#value'], 0), + '#description' => t('Enter an excerpt for this item. It will be shown on listing pages along with a read more link which leads to the full view. Leave empty to auto-generate one from the body.'), + ); + } + break; } }