Index: modules/field/modules/text/text.module =================================================================== RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.module,v retrieving revision 1.59 diff -u -p -r1.59 text.module --- modules/field/modules/text/text.module 7 Jul 2010 13:30:06 -0000 1.59 +++ modules/field/modules/text/text.module 18 Jul 2010 02:35:45 -0000 @@ -251,6 +251,7 @@ function text_field_formatter_info() { 'text_trimmed' => array( 'label' => t('Trimmed'), 'field types' => array('text', 'text_long', 'text_with_summary'), + 'settings' => array('trim_length' => 600), ), // The 'summary or trimmed' field formatter for text_with_summary @@ -260,11 +261,51 @@ function text_field_formatter_info() { 'text_summary_or_trimmed' => array( 'label' => t('Summary or trimmed'), 'field types' => array('text_with_summary'), + 'settings' => array('trim_length' => 600), ), ); } /** + * Implements hook_field_formatter_settings_form(). + */ +function text_field_formatter_settings_form($field, $instance, $view_mode) { + $display = $instance['display'][$view_mode]; + $settings = $display['settings']; + + $form = array(); + + if ($display['type'] == 'text_trimmed' || $display['type'] == 'text_summary_or_trimmed') { + $form['trim_length'] = array( + '#title' => t('Length'), + '#type' => 'textfield', + '#size' => 20, + '#default_value' => $settings['trim_length'], + '#element_validate' => array('_element_validate_integer_positive'), + '#required' => TRUE, + ); + } + + return $form; +} + +/** + * Implements hook_field_formatter_settings_summary(). + */ +function text_field_formatter_settings_summary($field, $instance, $view_mode) { + $display = $instance['display'][$view_mode]; + $settings = $display['settings']; + + $summary = ''; + + if ($display['type'] == 'text_trimmed' || $display['type'] == 'text_summary_or_trimmed') { + $summary = t('Length: @length characters', array('@length' => $settings['trim_length'])); + } + + return $summary; +} + +/** * Implements hook_field_formatter_view(). */ function text_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { @@ -273,23 +314,24 @@ function text_field_formatter_view($enti switch ($display['type']) { case 'text_default': case 'text_trimmed': + $size = isset($display['settings']['trim_length']) ? $display['settings']['trim_length'] : 600; foreach ($items as $delta => $item) { $output = _text_sanitize($instance, $langcode, $item, 'value'); if ($display['type'] == 'text_trimmed') { - $output = text_summary($output, $instance['settings']['text_processing'] ? $item['format'] : NULL); + $output = text_summary($output, $instance['settings']['text_processing'] ? $item['format'] : NULL, $size); } $element[$delta] = array('#markup' => $output); } break; case 'text_summary_or_trimmed': + $size = isset($display['settings']['trim_length']) ? $display['settings']['trim_length'] : 600; foreach ($items as $delta => $item) { if (!empty($item['summary'])) { $output = _text_sanitize($instance, $langcode, $item, 'summary'); } else { $output = _text_sanitize($instance, $langcode, $item, 'value'); - $size = variable_get('teaser_length_' . $instance['bundle'], 600); $output = text_summary($output, $instance['settings']['text_processing'] ? $item['format'] : NULL, $size); } $element[$delta] = array('#markup' => $output); Index: modules/node/content_types.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/node/content_types.inc,v retrieving revision 1.115 diff -u -p -r1.115 content_types.inc --- modules/node/content_types.inc 24 Jun 2010 22:23:06 -0000 1.115 +++ modules/node/content_types.inc 18 Jul 2010 02:35:45 -0000 @@ -207,13 +207,6 @@ function node_type_form($form, &$form_st '#default_value' => variable_get('node_submitted_' . $type->type, TRUE), '#description' => t('Author username and publish date will be displayed.'), ); - $form['display']['teaser_length'] = array( - '#type' => 'select', - '#title' => t('Length of trimmed content'), - '#default_value' => variable_get('teaser_length_' . $type->type, 600), - '#options' => drupal_map_assoc(array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000), '_node_characters'), - '#description' => t("The maximum number of characters used in the trimmed version of content.") - ); $form['old_type'] = array( '#type' => 'value', '#value' => $type->type, @@ -451,7 +444,6 @@ function node_type_delete_confirm($form, function node_type_delete_confirm_submit($form, &$form_state) { node_type_delete($form_state['values']['type']); - variable_del('teaser_length_' . $form_state['values']['type']); variable_del('node_preview_' . $form_state['values']['type']); $t_args = array('%name' => $form_state['values']['name']); drupal_set_message(t('The content type %name has been deleted.', $t_args)); Index: modules/node/node.install =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.install,v retrieving revision 1.51 diff -u -p -r1.51 node.install --- modules/node/node.install 14 May 2010 04:37:53 -0000 1.51 +++ modules/node/node.install 18 Jul 2010 02:35:46 -0000 @@ -674,6 +674,30 @@ function node_update_7010() { } /** + * Converts teaser_length variables to field formatter settings. + */ +function node_update_7011() { + $default_trim_length = variable_get('teaser_length', 600); + $node_types = node_type_get_names(); + foreach ($node_types as $node_type => $node_name) { + $trim_length = variable_get('teaser_length_' . $node_type, $default_trim_length); + if ($instance = field_info_instance('node', 'body', $node_type)) { + foreach ($instance['display'] as $view_mode => $view_mode_info) { + if ($view_mode_info['type'] == 'text_trimmed' || $view_mode_info['type'] == 'text_summary_or_trimmed') { + if (!isset($view_mode_info['settings']['trim_length'])) { + $instance['display'][$view_mode]['settings']['trim_length'] = $trim_length; + } + } + } + field_update_instance($instance); + } + variable_del('teaser_length_' . $node_type); + } + // Leave 'teaser_length' variable for aggregator module upgrade and + // text_summary() function. +} + +/** * @} End of "defgroup updates-6.x-to-7.x" * The next series of updates should start at 8000. */ Index: modules/node/node.test =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.test,v retrieving revision 1.89 diff -u -p -r1.89 node.test --- modules/node/node.test 8 Jul 2010 03:41:27 -0000 1.89 +++ modules/node/node.test 18 Jul 2010 02:35:46 -0000 @@ -565,11 +565,11 @@ class SummaryLengthTestCase extends Drup $expected = 'What is a Drupalism?'; $this->assertRaw($expected, t('Check that the summary is 600 characters in length'), 'Node'); - // Edit the teaser length for "Basic page" content type - $edit = array ( - 'teaser_length' => 200, - ); - $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); + // Change the teaser length for "Basic page" content type. + $instance = field_info_instance('node', 'body', $node->type); + $instance['display']['teaser']['settings']['trim_length'] = 200; + field_update_instance($instance); + // Attempt to access the front page again and check if the summary is now only 200 characters in length. $this->drupalGet("node"); $this->assertNoRaw($expected, t('Check that the summary is not longer than 200 characters'), 'Node'); @@ -1072,7 +1072,7 @@ class NodeTypeTestCase extends DrupalWeb $this->drupalGet('node/add/' . str_replace('_', '-', $type->name)); $this->assertResponse(200, 'The new content type can be accessed at node/add.'); - + // Create a content type via the user interface. $web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types')); $this->drupalLogin($web_user);