I have the following view:

$view = new view;
$view->name = 'test';
$view->description = '';
$view->tag = '';
$view->base_table = 'node';
$view->human_name = '';
$view->core = 0;
$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['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['distinct'] = TRUE;
$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'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'title' => 'title',
  'entity_id' => 'entity_id',
  'field_standort_city' => 'field_standort_city',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'title' => array(
    'sortable' => 0,
    'align' => '',
    'separator' => '',
  ),
  'entity_id' => array(
    'sortable' => 0,
    'align' => '',
    'separator' => '',
  ),
  'field_standort_city' => array(
    'align' => '',
    'separator' => '',
  ),
);
$handler->display->display_options['style_options']['override'] = 1;
$handler->display->display_options['style_options']['sticky'] = 0;
/* 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']['element_label_colon'] = 1;
$handler->display->display_options['fields']['title']['element_default_classes'] = 1;
$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: field_image */
$handler->display->display_options['fields']['entity_id']['id'] = 'entity_id';
$handler->display->display_options['fields']['entity_id']['table'] = 'field_data_field_image';
$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'] = 0;
$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']['element_label_colon'] = 1;
$handler->display->display_options['fields']['entity_id']['element_default_classes'] = 1;
$handler->display->display_options['fields']['entity_id']['hide_empty'] = 0;
$handler->display->display_options['fields']['entity_id']['empty_zero'] = 0;
$handler->display->display_options['fields']['entity_id']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['entity_id']['settings'] = array(
  'image_style' => 'thumbnail',
  'image_link' => 'content',
);
/* Filter: Beitrag: Typ */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'test' => 'test',
);

/* Display: Seite */
$handler = $view->new_display('page', 'Seite', 'page_1');
$handler->display->display_options['path'] = 'testview';
$translatables['test'] = array(
  t('Standards'),
  t('Weiter'),
  t('Anwenden'),
  t('Zurücksetzen'),
  t('Sort By'),
  t('Asc'),
  t('Desc'),
  t('Beträge pro Seite'),
  t('- All -'),
  t('Offset'),
  t('Titel'),
  t('field_image'),
  t('Seite'),
);

the view shows me all images of the node in the field_image column.

What must I do when I only want to show the first image?

Comments

bojanz’s picture

Status: Active » Fixed

Filter by delta.

klaus66’s picture

thats not possible

When I filter by delta = 0 then he shows me all nodes they have images and shows me all images in the field_image column.

I have now make it with a field template like so:

<?php
global $base_url;

if (empty($row->_field_data['nid']['entity']->field_kaz_image['und'][0])) {
  $thumb = theme('image_style', array('style_name'=>'thumb_treffer', 'path'=> variable_get('mini_default_image_uri')));
}
else {
	$thumb = theme('image_style', array('style_name'=>'thumb_treffer', 'path'=> $row->_field_data['nid']['entity']->field_kaz_image['und'][0]['uri']));
}

  $path = $base_url . '/node/' . $row->nid;  

  $output = '';
  $output .= '<div class="field-name-field-kaz-image">';
  $output .= l($thumb, $path, array('html' => TRUE));
  $output .= '</div>';

?>

<?php print $output; ?>
bojanz’s picture

Status: Fixed » Active

You're right.
There should be a way to handle your use case (in the future) I'll look into it

bojanz’s picture

Title: Show only one image in table » No way to render a single delta of a multivalue field
Version: 7.x-3.0-alpha1 » 7.x-3.x-dev
Component: Miscellaneous » fieldapi data
Category: feature » bug

So, how do we actually render a single delta? There's absolutely no way to do this!
field_view_field and the image formatters don't support this.
And of course, I realize this now that D7 is already released...

1) We need to kill the delta filter. It's completely useless.
2) A possible (but hacky) implementation would be to move delta to a field setting, then before rendering unset all other field value from the entity.
So if I want to display field_test, delta 1, the code does $entity->field_test = array($entity->field_test[1]). Every other delta gets killed.

Thoughts?

klaus66’s picture

I think the delta field was not completly useless.

I have a gallery view that shows only nodes with images and for this view I use the delta filter with field_image_delta = 0.

This shows me only the nodes that have images.

In drupal 6 views there was a setting option in the views UI to show only one image from a cck-imagefield

bojanz’s picture

Status: Active » Needs review
StatusFileSize
new5.02 KB

That crazy idea actually works. Patch attached. Needs polish.

Points to consider:
1) The option description (do users know what 'delta' is? What to tell them?)
2) We could add validation that ensures we either got a number or nothing as the option value.
3) We could display a dropdown of deltas if the field cardinality is limited. If it's unlimited, we could fallback on the current textfield.

Edit: Didn't see the reply above. Adding the filter works on filtering fields with no values because it forces the join to be made. The field option in my patch filters the query as well, so I removed the actual filter for consistency.

dawehner’s picture

StatusFileSize
new8.52 KB

This fixes the reference problem

The problem is if you have multiple times the same field. Then you alter the original $entity so you can't display for example delta0 and delta1 as extra fields.

This patch clones the $entity

dawehner’s picture


3) We could display a dropdown of deltas if the field cardinality is limited. If it's unlimited, we could fallback on the current textfield.

Done.

dawehner’s picture

StatusFileSize
new8.82 KB

Okay this time i give you the patch. CVS is so slow to diff

dawehner’s picture

Status: Needs review » Fixed

Commited to the 7.x branch.

bojanz’s picture

Another day, another job well done :)

bojanz’s picture

StatusFileSize
new1.09 KB

Quick followup.

dawehner’s picture

And commited.

klaus66’s picture

That works fine for me. Thanks.

But there is one problem about the language.

My image field is not translatable and when I set now the delta to 1 then I get the correct result with only one image in the record but also the following notice:

Notice: Undefined index: und in views_handler_field_field->render() (line 342 of D:\xampp\htdocs\hundekauf_drupal7_local\sites\all\modules\views\modules\field\views_handler_field_field.inc).
bojanz’s picture

Status: Fixed » Needs review
StatusFileSize
new742 bytes

This should fix it.

klaus66’s picture

Status: Needs review » Fixed

That works fine thank you

bojanz’s picture

Status: Fixed » Reviewed & tested by the community

You can't set it to fixed unless you've committed it yourself :P

dawehner’s picture

Status: Reviewed & tested by the community » Fixed

Thanks.

Commited to the 7.x branch.

morxe’s picture

This patch is on 7-dev ?.... if yes not good.. i receive a error..is not possible to insert any delta value...

siteogra’s picture

Error: An illegal choice has been detected. Please contact the site administrator.

:(

dawehner’s picture

Are you sure you have the version of the files of today? The dev version might not be ready yet.

morxe’s picture

Ok,the patch is 1019438-illegal_choice-fix.patch

Status: Fixed » Closed (fixed)

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

d0t15t’s picture

Has this been commited to the 7.x-3.x-dev Version? i'm still not able to limit the the multiple image field to just one image.

d0t15t’s picture

oops... nevermind i found it...

mjohnq3’s picture

Status: Closed (fixed) » Active

This still doesn't work as it did in Views 6. I have a content type that allows unlimited images and the view displays all of them contained in the node. I only want one displayed in the table view. I don't even care which one but just one! Is there any way to do this?

bojanz’s picture

Status: Active » Fixed

Yes. The latest dev version allows you to do exactly that. We made it behave like D6 yesterday.

mjohnq3’s picture

Thanks, I'll give that a try. I was using the latest alpha version.

** Update: This works fine now. Thanks so much - you made my day! **

Status: Fixed » Closed (fixed)

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

borfast’s picture

Status: Closed (fixed) » Active

I still have this problem with Views 7.x-3.x-dev (from March 2).

I have a content type with an image field that allows unlimited values.
I also have a view where I add the image field to a display and set the "Fields: field_image - delta" filter to use the operator "Is equal to" and the value "1".
The resulting view still shows all the images in each node instead of showing just one.

The SQL the view generates is a bit weird:
SELECT node.nid AS nid, 'node' AS field_data_field_client_node_entity_type, 'node' AS field_data_field_image_node_entity_type FROM {node} node LEFT JOIN {field_data_field_image} field_data_field_image ON node.nid = field_data_field_image.entity_id AND (field_data_field_image.entity_type = :views_join_condition_0 AND field_data_field_image.deleted = :views_join_condition_1) WHERE (( (node.status = '1') AND (node.type IN ('project')) AND (field_data_field_image.delta = '') )) LIMIT 10 OFFSET 0

Shouldn't those ":views_join_condition_" be replaced somewhere by some other values?
And shouldn't the "field_data_field_image.delta = ''" at the end be "field_data_field_image.delta = '1'" instead?
Also, I've read in one of these comments that you had added a dropdown list to select the delta, when the user defines a specific maximum value for the field (as opposed to unlimited) but I always see a regular textbox, even when I change the field definition to a fixed maximum value instead of unlimited.

bojanz’s picture

- Shouldn't those ":views_join_condition_" be replaced somewhere by some other values?
No. It's just shown that way, it's the way PDO works.

And shouldn't the "field_data_field_image.delta = ''" at the end be "field_data_field_image.delta = '1'" instead?
Yes. Sounds like a bug.

Do you want to show only one image for the node, or one image per row for the node?

borfast’s picture

Oh, right, I forgot about PDO in D7. No harm there, then. :)

Do you want to show only one image for the node, or one image per row for the node?
I'm not sure I understand the difference.
The content type has an image field which allows unlimited images - I want the view to generate a page with all the nodes of that content type, and for each node, I want it to show the first image of its image field/set (so yes, I should set the delta to 0 instead of 1).

I can export the view and put it here, if it helps.

klaus66’s picture

You can do all settings in the Views UI to get the result you want.

The important fieldset in the UI is "Multiple Field settings"

There you must set:

1.Check "Display all values in the same row"
2. Display 1 value starting from 0

That was it.

Here is a test view for you where you can see the settings:

$view = new view;
$view->name = 'test';
$view->description = '';
$view->tag = '';
$view->base_table = 'node';
$view->human_name = '';
$view->core = 0;
$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['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['distinct'] = TRUE;
$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'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'title' => 'title',
  'entity_id' => 'entity_id',
  'entity_id_1' => 'entity_id_1',
  'entity_id_2' => 'entity_id_2',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'title' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'entity_id' => array(
    'align' => '',
    'separator' => '',
  ),
  'entity_id_1' => array(
    'sortable' => 1,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'entity_id_2' => array(
    'sortable' => 1,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
);
$handler->display->display_options['style_options']['override'] = 1;
$handler->display->display_options['style_options']['sticky'] = 0;
/* 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']['element_label_colon'] = 1;
$handler->display->display_options['fields']['title']['element_default_classes'] = 1;
$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: Unlimit images */
$handler->display->display_options['fields']['field_unlimited_images']['id'] = 'field_unlimited_images';
$handler->display->display_options['fields']['field_unlimited_images']['table'] = 'field_data_field_unlimited_images';
$handler->display->display_options['fields']['field_unlimited_images']['field'] = 'field_unlimited_images';
$handler->display->display_options['fields']['field_unlimited_images']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_unlimited_images']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_unlimited_images']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_unlimited_images']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_unlimited_images']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_unlimited_images']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_unlimited_images']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_unlimited_images']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_unlimited_images']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_unlimited_images']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_unlimited_images']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_unlimited_images']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_unlimited_images']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_unlimited_images']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_unlimited_images']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_unlimited_images']['settings'] = array(
  'image_style' => 'thumb_gallery',
  'image_link' => '',
);
$handler->display->display_options['fields']['field_unlimited_images']['group_rows'] = 1;
$handler->display->display_options['fields']['field_unlimited_images']['delta_limit'] = '1';
$handler->display->display_options['fields']['field_unlimited_images']['delta_offset'] = '0';
$handler->display->display_options['fields']['field_unlimited_images']['delta_reversed'] = 0;
$handler->display->display_options['fields']['field_unlimited_images']['field_api_classes'] = 0;
/* Filter: Beitrag: Typ */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'test' => 'test',
);

/* Display: Seite */
$handler = $view->new_display('page', 'Seite', 'page_1');
$handler->display->display_options['path'] = 'testview';
$translatables['test'] = array(
  t('Standards'),
  t('Weiter'),
  t('Anwenden'),
  t('Zurücksetzen'),
  t('Sort By'),
  t('Asc'),
  t('Desc'),
  t('Beträge pro Seite'),
  t('- All -'),
  t('Offset'),
  t('Titel'),
  t('Unlimit images'),
  t('Seite'),
);

dawehner’s picture

Status: Active » Fixed

Mark as fixed based on the comment.

borfast’s picture

Got it. Hadn't seen the "Multiple Field settings" thing before. Thanks! :)

itrain’s picture

Category: bug » support

Can anyone help me find the "Multiple Field Settings" in views UI please? I've been searching and clicking around for 2 hours, can't find it. I'm on latest version of views/D7.

I am creating a block view, with an image field (which is set to have unlimited images), but only want to display 1 image in the block view. Tried filtering delta = 1 but does not work. It sounds like Multiple field settings is what I'm looking for?

Thanks.

bojanz’s picture

Please stop raising this issue from the dead. It's driving me crazy.

The Multiple Field Settings are in the field settings (when you click on your imagefield, it's there, near the bottom). You need the latest -devs, which you say you have.

itrain’s picture

Very sorry, I hate re-raising issues but not finding it was driving me crazy too. I was using alpha, not dev - my bad (thought alpha would have had it), replaced alpha folder with dev and now it's there. Thank you anyway.

bojanz’s picture

Status: Fixed » Closed (fixed)

Just open a new issue with your support request the next time, and you'll be fine :)