Hi there,

I was wondering if we can add an option to trim the field's output before printing it out.
Like the default trimming option the core already has.
If it makes sense, I created a patch as a starting point.

Thank you!

Comments

apanag’s picture

Issue summary: View changes
StatusFileSize
new2.51 KB
cornelyus’s picture

I came to the issues looking exactly for this.. when I have linked and wrapped but in some occasions need to trim also.

Updated module to dev version, applied path with netbeans but have myself an error on title.field.inc

Looked to patch and here

@@ -103,6 +133,16 @@ function title_field_formatter_view($entity_type, $entity, $field, $instance, $l
   if (!empty($output)) {
     if ($settings['title_link'] == 'content') {
       $uri = entity_uri($entity_type, $entity);
+
+      // If trimmed is enabled.
+      if ($settings['enable_trim']) {
+      $trimmed_output = text_summary($output, $instance['settings']['text_processing'] ? $item['format'] : NULL, $display['settings']['trim_length']);
+
+      // If we performed trimmed, add ellipsis in the end.
+      if (drupal_strlen($output) != drupal_strlen($trimmed_output)) {
+        $output = $trimmed_output . '…';
+      }
+
       $output = l($output, $uri['path'], array('html' => TRUE));
     }
 

is it missing } to close the if?

apanag’s picture

Hi cornelyus!

You 're right. I can see the bracket in my code, but not in the patch (strange).
I will upload a new patch in a few mins.

Thanks for mentioning it.

apanag’s picture

StatusFileSize
new2.53 KB

Here it is.

cornelyus’s picture

no problem,

thank you!

jsacksick’s picture

Status: Active » Needs review
StatusFileSize
new2.51 KB

I found an issue with the path, $item['format'] is not defined. When you apply the patch you get a lot of warnings if you previously had title fields set up, I added a !empty check in order to fix this.

pol’s picture

Status: Needs review » Reviewed & tested by the community

Hi,

Thanks for the patch, it makes sense.

alex_optim’s picture

+1

pifagor’s picture

Assigned: Unassigned » pifagor
pifagor’s picture

  • pifagor committed 72c55a8 on 7.x-1.x
    Issue #2270177 by apanag, jsacksick, pifagor, cornelyus, Pol, alex_optim...
pifagor’s picture

Status: Reviewed & tested by the community » Fixed

I was forced to rebuild the patch

Status: Fixed » Closed (fixed)

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