I have a field collection with the number set to Unlimited such that I can "Add More" of them while editing. The weights seem to be totally ignored in how they are displayed when using this module. The weights are saved just fine (I can see on the edit page where the ordering is correct) and other display methods (e.g. Table, Embedded) also display the fields in the correct order. On the other hand, this module ignores the weights and displays the field collections strictly in the order they were created. I'm not sure if there's some setting in the View I'm using that would allow for this to work based on the weights. I tried a variety of sorting options in the view but nothing worked so far.
Comments
Comment #1
piwchix CreditAttribution: piwchix commentedI have excactly same problem. Tried to agregate, unagregate JS, disable enable, different modules.
It works with simple CCK fields, but doesn't work with multiple field collection as CKK field.
Comment #2
g089h515r806 CreditAttribution: g089h515r806 commentedI have test with this situation:
1,i have a resume profile type which have a work experience field collection field.
2, in work experience field collection, there are some other field, such as" company name", "duration",all of the is single value.
3,when i change duration from single value to multi value,
4,the views does not work correctly as my expectation.
Is this the same issue compared with yours?
THis is not a bug of this module, this is a bug of field collection or entity API. it already exist when i start build this module.
Comment #3
g089h515r806 CreditAttribution: g089h515r806 commentedThis module is an addon for E-recruiter installation profile, I have test it on this profile. Multiple Value issue already exist when i build this module.
Comment #4
thirdboxcar CreditAttribution: thirdboxcar commentedI'm not sure this is an issue of the original Field Collection module...when I make a normal View on the field (unlimited field collection) they order correctly, but this View has no ability to sort by the top level delta. I can access all the child Field Collection deltas through your View, which is great, but not the top level.
Comment #5
Marco G. CreditAttribution: Marco G. commentedI have the same needs, and it's not possible to access the Field Collection delta of top level field, but only the Filed Collection Item Id, which is the value used to order the View as default.
So I tried to add the delta top level field, making some changes to the module files. Now I can display the delata value as a view field and it works fine.
I can also add the field as sorting and filtering field, but when I do this I receive the following error in the view result:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_collection_item.delta' in 'field list' (where delta is the name I gived to the field)
Following the change I've done to modules file:
1) created "field_collection_views_handler_field_delta.inc" as follows:
class field_collection_views_handler_field_delta extends views_handler_field {
function query() {
// Do nothing, as this handler does not need to do anything to the query itself.
}
function option_definition() {
$options = parent::option_definition();
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
}
/**
* Work out the ITEM ID Delta
*/
function render($values) {
$field_path = "";
$item_id = $values->item_id;
//debug($values);
$field_collection_item = field_collection_item_load($item_id);
// $delta = field_collection_field_get_path($field_collection_item->delta());
$delta = $field_collection_item->delta();
return $delta;
}
}
2) added in "field_collection_views.info" the line to include
files[] = views/field_collection_views_handler_field_delta.inc
3) added in "field_collection_views.views.inc" the following function:
$data['field_collection_item']['delta'] = array(
'title' => t('Item id - Delta'),
'help' => t('The delta value of Item ID.'),
'field' => array(
'handler' => 'field_collection_views_handler_field_delta',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
I'm not so skilled on drupal, php, ecc. but it seems I'm at a step from the solution...has anyone an idea about how to complete this work??
Comment #6
css117 CreditAttribution: css117 commentedHello,
I would be very interested by this function too.
It looks native, instead of using draggable view : the weight info and the admin section work allready fine thanks to field collection implementation.
We "just" need to have the weight field accessible in the sorting criteria.
Btw the delta isn't available :/
It would be sad to have to add a new integer field to handle it manually...
Thanks in advance !
Comment #7
Watergate CreditAttribution: Watergate commentedI don't think this is a shortcoming of the Field Collection Views module. In the field's formatter the arguments are provided in the order of the delta (i.e., weight) value (to View's contextual filter). Although I haven't looked in much detail in the way Views generates the SQL query, it seems that the standard way is using the plain IN operator (which, logically, doesn't look at the way the parameters are ordered).
However, to make the ordering respect the top level delta values, I have created a relationship to the top level entity in the view that generates the output for the Field Collection field. This relationship is with 'Field collection item: Entity with the {Field Collection field}' and marked required. This works in all my use cases, hopefully it does for you too :)
Comment #8
joelcollinsdc CreditAttribution: joelcollinsdc commented@#7 i couldn't get this to work... what are you sorting by?
Comment #9
Watergate CreditAttribution: Watergate commentedI don't have anything in the sort criteria.
The view generating the field collection item, has the mentioned required relationship (see #7). (BTW, don't forget to check 'Allow multiple values' when configuring the contextual filter)
In the top level view, I use the formatter provided by the Field Collection View module and checked the multi-field settings to display the results in the same row.
Comment #10
Synerverse CreditAttribution: Synerverse commented@#7 Bingo!!!!! That's the ticket! Thank you MrWatergate for finding that!
Comment #11
shashank7 CreditAttribution: shashank7 commented#7 worked great. Thanks MrWatergate.
Comment #12
bpadaria CreditAttribution: bpadaria commented#7 worked for me too. Thanks MrWatergate.
Comment #13
mrP CreditAttribution: mrP commented@MrWatergate -- superb! thanks a ton for #7
Comment #14
sigkg CreditAttribution: sigkg commentedHi.
The grouping for mine isn't working on the 3rd level.
This is with Delta 2
1. Item 1
1.1
1.2
1.2.1
1.2.2
With Delta All:
1. Item 1
1.1
1.2
1.1.1
1. Item 1
1.1
1.2
1.2.1
1.2.2
It appears it doesn't know that 1.1.1 belongs under 1.1. Can it because this was typed in after everything else was.
Thanks
Comment #15
sigkg CreditAttribution: sigkg commentedForgot to mention:
The sub-sub-item (1.2.1) is on Delta 2 with the Field collection item: Sub-item (1.1) Without the relationship the sub-sub-item doesn't appear.
Comment #16
code-drupal CreditAttribution: code-drupal commentedThe ordering can be achieved for field collection view in a custom ways by altering the views query
The above function will order it as per the requirement based on the field collection ids passed.
Comment #17
code-drupal CreditAttribution: code-drupal commentedThe ordering can be achieved for field collection view in a custom ways by altering the views query
The above function will order it as per the requirement based on the field collection ids passed.
Comment #18
Anonymous (not verified) CreditAttribution: Anonymous commentedTried this but nothing happends.
What's the point in being able to move items when they're not being saved?
Comment #19
Anonymous (not verified) CreditAttribution: Anonymous commentedHow to solve this issue?
Comment #20
mareks CreditAttribution: mareks commentedI only needed to a relationship to my field collection item. AND I also had to check the "Require this relationship". I don't have anything in sorting criteria but my view still respects the row order (weight) in the collection.
Comment #21
bpadaria CreditAttribution: bpadaria commentedThanks MrWatergate.
Comment #7 worked for me as well.
Comment #22
mikemccaffreyThis is still an issue. There needs to be a sort criteria for making field collection items display in the proper order.
Even after following the instructions in #7 there is nothing in the query that would ensure that items are sorted properly by the delta field:
Comment #23
mikemccaffreyHere is the query if I take the same view as above and add a sort criteria on the delta of the field instance in a related node:
The problem is that when adding the sort condition, it assumes that the view type is for nodes, and not the field collection, so it goes to merge the field collection onto the nodes that have been already merged onto the field collections. This means that if you have 5 records, you get 25 results, as each record is joined to every other one.
How can we make a sort available for the delta on the field collection in its relationship to the node, rather than on the node's relationship to to the field collection field?
Comment #24
ron_s CreditAttribution: ron_s commented@mikemccaffrey, I think you might be facing the issue I've seen quite a few times.
The problem has to do with the base table selected for building the View. When adding a new view, users are presented a "Show" dropdown selection that allows for an entity to be selected. This selection serves as the foundation for building the rest of the view.
If Field collection item is picked, there will be extremely unpredictable results. I've seen situations where random
LEFT JOIN
s are added, result rows are duplicated many items, and sorting becomes impossible.The correct approach that has worked for me every time is select the entity or node as the base table, and then build a connection to the field collections using the Views relationships. From there, the
field:delta
option can be used to sort the field collection information appropriately.Comment #25
joshuautley CreditAttribution: joshuautley commentedRon, I was build a view with a Profile base table and used a relationship to the field collection based on your comment above (#24). That was the ticket to bring in the delta values so I could filter and sort. Thank you!!!
Comment #26
airb CreditAttribution: airb commented#24: "field:delta" is field collection weight, thanks!
Comment #27
maxplus CreditAttribution: maxplus commentedHi,
for me it worked to add the relationship to the host entity (node) and add a sorting criterium on the delta
Thanks!
Comment #28
FrancewhoaAnother option we found at https://www.drupal.org/node/1391938#comment-11386501
Comment #29
kellyimagined CreditAttribution: kellyimagined as a volunteer commented#27 provides instructions on how to complete.
Comment #30
Eric At NRD CreditAttribution: Eric At NRD as a volunteer commentedI could not get #7 to work right for my use case. However, an alternate method using hook_views_post_execute() DID work for me:
https://www.drupal.org/project/field_collection_views/issues/2075593#com...
I post this here only in case others ran into circumstances where #7 did not work.