summaryrefslogtreecommitdiff
path: root/modules/field
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-08-08 13:02:37 +0000
committerDries Buytaert <dries@buytaert.net>2010-08-08 13:02:37 +0000
commitf0b3fa4b1bb0b8c91424c3ad36dfef592ccbc954 (patch)
tree84679f95714d6b04ee10442ffc255c4b5bd1b4d2 /modules/field
parentf885d9f7dca9242b7906d6d441cae5feb2aba5b1 (diff)
downloadbrdo-f0b3fa4b1bb0b8c91424c3ad36dfef592ccbc954.tar.gz
brdo-f0b3fa4b1bb0b8c91424c3ad36dfef592ccbc954.tar.bz2
- Patch #504564 by tic2000, andypost, catch: the 'Length of trimmed content'
form input in the 'node type' edit form was way too harsh (affects the display of all 'trimmed / summary_or_trimmed' formatters on all text fields in all view modes), and irrelevant for text fields on non-node entities, which are currently all blocked to 'trim to 600 chars'. * Added field formatter settings for 'text_trimmed' and 'text_summary_or_trimmed' formatters * Removed 'teaser_length' settings for node types * Added upgrade path for 'teaser_length' variable in node_update_7011() * Fixed a test
Diffstat (limited to 'modules/field')
-rw-r--r--modules/field/modules/text/text.module46
1 files changed, 43 insertions, 3 deletions
diff --git a/modules/field/modules/text/text.module b/modules/field/modules/text/text.module
index d08b311ce..5862ae920 100644
--- a/modules/field/modules/text/text.module
+++ b/modules/field/modules/text/text.module
@@ -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, $form, &$form_state) {
+ $display = $instance['display'][$view_mode];
+ $settings = $display['settings'];
+
+ $form = array();
+
+ if (strpos($display['type'], '_trimmed') !== FALSE) {
+ $form['trim_length'] = array(
+ '#title' => t('Trim length'),
+ '#type' => 'textfield',
+ '#size' => 10,
+ '#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 (strpos($display['type'], '_trimmed') !== FALSE) {
+ $summary = t('Trim length') . ': ' . $settings['trim_length'];
+ }
+
+ return $summary;
+}
+
+/**
* Implements hook_field_formatter_view().
*/
function text_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
@@ -276,7 +317,7 @@ function text_field_formatter_view($entity_type, $entity, $field, $instance, $la
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, $display['settings']['trim_length']);
}
$element[$delta] = array('#markup' => $output);
}
@@ -289,8 +330,7 @@ function text_field_formatter_view($entity_type, $entity, $field, $instance, $la
}
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);
+ $output = text_summary($output, $instance['settings']['text_processing'] ? $item['format'] : NULL, $display['settings']['trim_length']);
}
$element[$delta] = array('#markup' => $output);
}