When adding a date field in views with multiple values and you define start&stop and/or number of values to show iv found a rather annoying "bugg".
Lets assume you select to show only 1 value starting from a given date...
in date.module in function "date_prepare_entity" where we remove unwanted values the code assumes the order of this date field array is what we want to loop through.
What if the dates is added to the field in wrong order for example:
2014-01-24
2014-01-22
2014-01-26
and we want to show 1 date starting from 2014-01-20 ...
Then the result would be 2014-01-24 ... when in theory we want to show 2014-01-22 ..
in my case i fixed this by sortering the array by dates before the loop runs... with this code:
// Sort array based on start dates
if(sizeof($entity->{$field_name}[$langcode]) > 1) {
uasort($entity->{$field_name}[$langcode], function($a, $b) {
return ($a['value'] < $b['value']) ? -1 : 1;
});
}
I think this should be standard or atleast be an option to choose in views field settings.
Comment | File | Size | Author |
---|---|---|---|
#2 | Multiple_date_sort-2183497-2.patch | 5.97 KB | Kovalevich.Artem |
#2 | Views setting fields.png | 49.76 KB | Kovalevich.Artem |
Comments
Comment #1
eugene.ilyin CreditAttribution: eugene.ilyin commentedComment #2
Kovalevich.Artem CreditAttribution: Kovalevich.Artem commentedHello
I solved this problem.
Now it's possible, sort the dates in field via the new selectbox, which located on the settings form of the field (in views and in formatter).
Comment #4
eugene.ilyin CreditAttribution: eugene.ilyin commentedComment #5
eugene.ilyin CreditAttribution: eugene.ilyin commentedLet's check patch again on the dev version
Comment #6
podarokShould be fixed. Do not pass tests (
Comment #9
andriyun CreditAttribution: andriyun commented