When I checked "Trim this field to a maximum length" I get no output.
My field was the bodyfield and the maxlength 110.

CommentFileSizeAuthor
#16 view_bug.png125.34 KBngmaloney

Comments

Letharion’s picture

Status: Active » Closed (cannot reproduce)

Please read the issue submission guidelines.

I can't reproduce problems without a view and the data you run the view on.

klaus66’s picture

Status: Closed (cannot reproduce) » Active

Here is the view. My system local is a WAMP.

$view = new view;
$view->name = 'kaz_search';
$view->description = 'Stellt die Trefferliste des Kleinanzeigenmarktes bereit ';
$view->tag = '';
$view->base_table = 'node';
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Standards */
$handler = $view->new_display('default', 'Standards', 'default');
$handler->display->display_options['use_more_text'] = 'Weiter';
$handler->display->display_options['group_by'] = TRUE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['exposed_form']['options']['reset_button_label'] = 'Zurücksetzen';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['expose']['items_per_page_label'] = 'Beträge pro Seite';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Feld: Felder: field_kaz_image */
$handler->display->display_options['fields']['entity_id_1']['id'] = 'entity_id_1';
$handler->display->display_options['fields']['entity_id_1']['table'] = 'field_data_field_kaz_image';
$handler->display->display_options['fields']['entity_id_1']['field'] = 'entity_id';
$handler->display->display_options['fields']['entity_id_1']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['entity_id_1']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['entity_id_1']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['entity_id_1']['alter']['trim'] = 0;
$handler->display->display_options['fields']['entity_id_1']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['entity_id_1']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['entity_id_1']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['entity_id_1']['alter']['html'] = 0;
$handler->display->display_options['fields']['entity_id_1']['hide_empty'] = 0;
$handler->display->display_options['fields']['entity_id_1']['empty_zero'] = 0;
$handler->display->display_options['fields']['entity_id_1']['settings'] = array(
  'image_style' => 'thumbnail',
  'image_link' => 'content',
);
/* Feld: Felder: field_kaz_image */
$handler->display->display_options['fields']['entity_id_2']['id'] = 'entity_id_2';
$handler->display->display_options['fields']['entity_id_2']['table'] = 'field_data_field_kaz_image';
$handler->display->display_options['fields']['entity_id_2']['field'] = 'entity_id';
$handler->display->display_options['fields']['entity_id_2']['group_type'] = 'count';
$handler->display->display_options['fields']['entity_id_2']['exclude'] = TRUE;
$handler->display->display_options['fields']['entity_id_2']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['entity_id_2']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['entity_id_2']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['entity_id_2']['alter']['trim'] = 0;
$handler->display->display_options['fields']['entity_id_2']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['entity_id_2']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['entity_id_2']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['entity_id_2']['alter']['html'] = 0;
$handler->display->display_options['fields']['entity_id_2']['hide_empty'] = 0;
$handler->display->display_options['fields']['entity_id_2']['empty_zero'] = 0;
$handler->display->display_options['fields']['entity_id_2']['settings'] = array(
  'image_style' => '',
  'image_link' => '',
);
/* Feld: Beitrag: Titel */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Feld: Felder: body */
$handler->display->display_options['fields']['entity_id']['id'] = 'entity_id';
$handler->display->display_options['fields']['entity_id']['table'] = 'field_data_body';
$handler->display->display_options['fields']['entity_id']['field'] = 'entity_id';
$handler->display->display_options['fields']['entity_id']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['entity_id']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['entity_id']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['entity_id']['alter']['trim'] = 1;
$handler->display->display_options['fields']['entity_id']['alter']['max_length'] = '110';
$handler->display->display_options['fields']['entity_id']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['entity_id']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['entity_id']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['entity_id']['alter']['html'] = 0;
$handler->display->display_options['fields']['entity_id']['hide_empty'] = 0;
$handler->display->display_options['fields']['entity_id']['empty_zero'] = 0;
/* Feld: Felder: field_standort */
$handler->display->display_options['fields']['entity_id_4']['id'] = 'entity_id_4';
$handler->display->display_options['fields']['entity_id_4']['table'] = 'field_data_field_standort';
$handler->display->display_options['fields']['entity_id_4']['field'] = 'entity_id';
$handler->display->display_options['fields']['entity_id_4']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['entity_id_4']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['entity_id_4']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['entity_id_4']['alter']['trim'] = 0;
$handler->display->display_options['fields']['entity_id_4']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['entity_id_4']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['entity_id_4']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['entity_id_4']['alter']['html'] = 0;
$handler->display->display_options['fields']['entity_id_4']['hide_empty'] = 0;
$handler->display->display_options['fields']['entity_id_4']['empty_zero'] = 0;
/* Feld: Beitrag: Aktualisierungszeitpunkt */
$handler->display->display_options['fields']['changed']['id'] = 'changed';
$handler->display->display_options['fields']['changed']['table'] = 'node';
$handler->display->display_options['fields']['changed']['field'] = 'changed';

/* Display: Seite */
$handler = $view->new_display('page', 'Seite', 'page_1');
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'entity_id_1' => 'entity_id_1',
  'title' => 'title',
  'entity_id' => 'entity_id',
  'entity_id_2' => 'entity_id_2',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'entity_id_1' => array(
    'sortable' => 0,
    'align' => '',
    'separator' => '',
  ),
  'title' => array(
    'sortable' => 0,
    'align' => '',
    'separator' => '',
  ),
  'entity_id' => array(
    'sortable' => 0,
    'align' => '',
    'separator' => '',
  ),
  'entity_id_2' => array(
    'sortable' => 0,
    'align' => '',
    'separator' => '',
  ),
);
$handler->display->display_options['style_options']['override'] = 1;
$handler->display->display_options['style_options']['sticky'] = 0;
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['path'] = 'announce/%/%';

merlinofchaos’s picture

Does the value you're trimming contain HTML? This is the leading cause of the problem you are seeing.

didox’s picture

I have had the same problem and I ticked (provisionally) 'Strip HTML tags' and is ok. (I didn't use any html tag inside post) - strangely

my source html:

<div class="content">
    <div class="field field-name-field-image2 field-type-image field-label-hidden"><div class="field-items"><div class="field-item even"><img typeof="foaf:Image" src="xxx" alt="" /></div></div></div><div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Quae populus interdico similisncidunt si abigo gilvus elit cui.Suscipit autem eu quae iaceo luptatum cui causa.  abigo eum</p>
</div></div>
Letharion’s picture

Assigned: klaus66 » merlinofchaos

@merlin
Could you please elaborate on "Is the leading cause"? I assume that trimming is supposed to be supported even with HTML, is it not?
Will this be fixed later, or is this "as designed"?

klaus66’s picture

In drupal 6 views it was no problem to trim the body. With or without html.

I think the body field is the most important field to trim.

klaus66’s picture

No I set the field to plain text and I control it with firebug and there was no html inside the body field.

merlinofchaos’s picture

Assigned: merlinofchaos » dawehner

Often times you'll see stuff like this:


some long link text

And if it gets cut in the URL, the entire thing ends up cut because malformed tags are removed.

However, from the sound of this, it appears that there may be a bug in D7. Kicking this over to dereine to take a look at.

klaus66’s picture

When you check "Strip HTML tags " in the Views UI then it works.

dawehner’s picture

As you see

<div class="content">
    <div class="field field-name-field-image2 field-type-image field-label-hidden"><div class="field-items"><div class="field-item even"><img typeof="foaf:Image" src="xxx" alt="" /></div></div></div><div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>

This is just html without any content. This html is ~400 long, so truncating just returns html, without content.

So i guess the status should be "works as designed".

dawehner’s picture

Status: Active » Closed (works as designed)

Change the status is right.

Argus’s picture

Status: Active » Closed (works as designed)

Forgive me for re-opening when there's probably tuns of important stuff for you to attend to, but why do you consider HTML output to be part of the field's content?

Shouldn't the trimming happen only on the text that is in the field?

Argus’s picture

Status: Closed (works as designed) » Active

see above

bojanz’s picture

In Drupal 7, Views doesn't render the field, that is done by Drupal 7 itself, and Views just passes it along.
So, the "trim" option is kinda useless for fields, since that should be done by the field formatter itself (Views allows you to select an appropriate formatter and change it's settings when adding a field. In this case it's the "Trimmed" formatter).

bojanz’s picture

Status: Closed (works as designed) » Active

Here's a suggestion:

Remove the:
1. Trim this field to a maximum length
2. Strip HTML tags (actually, no real reason to remove this one)
options for Field API fields. This is already done by formatters, and duplicating it only causes confusion like above.

I know that a Field might not have a Trimmed formatter or whatever, but the point is that Views should leave these things to formatters.
A field tells us how it wants or can be rendered, we pass the choice to the user, without guessing anything.
Separation of concerns, nothing more or less.

Will roll a patch in the next 24h, giving you all time to disagree (and merlinofchaos and dereine to "won't fix" it if they think I'm insane)

ngmaloney’s picture

StatusFileSize
new125.34 KB

I was having the same issue; adding a text field and trimming length would display empty text when rendered. The catch was this was only happening on our development server, not my local MAMP install. Upon further inspection I discovered that when running php 5.3 truncation worked fine but when running php 5.2.x it would not work at all.

Running:
Drupal: 7.0
Views: 7.x-3.0-alpha1
Ctools: 7.x-1.0-alpha2

View code is here. Attached is a screen shot of the blocks to illustrate bug.

dawehner’s picture

1. Trim this field to a maximum length
2. Strip HTML tags (actually, no real reason to remove this one)
options for Field API fields

Mh. It's a common use for many users.
So you force every formatter for any kind of field to have the trim functionality.

For example if there would be a formatter for image description, you would need trim there, which really is kind of interesting.
Makes this sense? Perhaps you was just in the "oh fieldapi integration is totally broken"-mode :)

Sunlight Studios’s picture

Exactly the same symptoms here, everything working perfectly on my laptop running 5.3, empty output on live server running 5.2 - I managed to track the problem down to PHP's own mb_substr() function but have yet to figure out why it's acting this way or how to get around it.

Basically the Views handler calls views_trim_text() which calls drupal_substr() which calls mb_substr(). I'm new to developing for D7 so I don't know how feasible it is to pull out the full length of content with Views and then use custom code to trim it, perhaps in template.php or in a field template file somewhere... am looking into it today as I need a quick fix!

merlinofchaos’s picture

Interesting. I'm not having a problem trimming fields with the latest code, running PHP 5.2.something.

merlinofchaos’s picture

Status: Active » Closed (won't fix)

If you've got a PHP with a broken mb_substr() there really isn't anything we can do about that anyway, except urge you to get a non-broken PHP version. :)

To address earlier comments: We can't parse the HTML to see what is content and what isn't and trim only that content. That's a level of intelligence that we're simply not going to code up and not going to force on users who don't need it, wasting CPU cycles.

johnpitcairn’s picture

If you do want to waste CPU cycles parsing the html to trim only user-visible content, I've been having some initial success with code from http://snippets.dzone.com/posts/show/7125, used in hook_views_pre_render() on the appropriate text field's ['rendered']['#markup'].