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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eugene.ilyin’s picture

Assigned: Unassigned » eugene.ilyin
Kovalevich.Artem’s picture

Status: Needs work » Needs review
FileSize
49.76 KB
5.97 KB

Hello

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).
screenshot

Status: Needs review » Needs work

The last submitted patch, 2: Multiple_date_sort-2183497-2.patch, failed testing.

eugene.ilyin’s picture

Version: 7.x-2.6 » 7.x-2.x-dev
eugene.ilyin’s picture

Status: Needs work » Needs review

Let's check patch again on the dev version

podarok’s picture

Status: Needs review » Needs work

Should be fixed. Do not pass tests (

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: Multiple_date_sort-2183497-2.patch, failed testing.

andriyun’s picture

Assigned: eugene.ilyin » Unassigned