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
Comment #1
bojanz commentedFilter by delta.
Comment #2
klaus66 commentedthats 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:
Comment #3
bojanz commentedYou're right.
There should be a way to handle your use case (in the future) I'll look into it
Comment #4
bojanz commentedSo, 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?
Comment #5
klaus66 commentedI 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
Comment #6
bojanz commentedThat 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.
Comment #7
dawehnerThis 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
Comment #8
dawehnerDone.
Comment #9
dawehnerOkay this time i give you the patch. CVS is so slow to diff
Comment #10
dawehnerCommited to the 7.x branch.
Comment #11
bojanz commentedAnother day, another job well done :)
Comment #12
bojanz commentedQuick followup.
Comment #13
dawehnerAnd commited.
Comment #14
klaus66 commentedThat 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:
Comment #15
bojanz commentedThis should fix it.
Comment #16
klaus66 commentedThat works fine thank you
Comment #17
bojanz commentedYou can't set it to fixed unless you've committed it yourself :P
Comment #18
dawehnerThanks.
Commited to the 7.x branch.
Comment #19
morxe commentedThis patch is on 7-dev ?.... if yes not good.. i receive a error..is not possible to insert any delta value...
Comment #20
siteogra commentedError: An illegal choice has been detected. Please contact the site administrator.
:(
Comment #21
dawehnerAre you sure you have the version of the files of today? The dev version might not be ready yet.
Comment #22
morxe commentedOk,the patch is 1019438-illegal_choice-fix.patch
Comment #24
d0t15t commentedHas 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.
Comment #25
d0t15t commentedoops... nevermind i found it...
Comment #26
mjohnq3 commentedThis 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?
Comment #27
bojanz commentedYes. The latest dev version allows you to do exactly that. We made it behave like D6 yesterday.
Comment #28
mjohnq3 commentedThanks, 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! **
Comment #30
borfast commentedI 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 0Shouldn'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.
Comment #31
bojanz commented- 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?
Comment #32
borfast commentedOh, 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.
Comment #33
klaus66 commentedYou 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:
Comment #34
dawehnerMark as fixed based on the comment.
Comment #35
borfast commentedGot it. Hadn't seen the "Multiple Field settings" thing before. Thanks! :)
Comment #36
itrain commentedCan 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.
Comment #37
bojanz commentedPlease 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.
Comment #38
itrain commentedVery 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.
Comment #39
bojanz commentedJust open a new issue with your support request the next time, and you'll be fine :)