This is a proposed patch for date_views.inc to deal with this issue http://drupal.org/node/101050 for date fields. Hopefully there is a general-purpose solution coming, but in the meantime, this patch might help others.

This is particularly useful for dates because if an optional date field is not set, then the node should not show up on date-oriented views (like "upcoming events", for example).
The strncmp operator test feels a bit of a hack - probably more elegant way to handle this? Sorry the patch is 'by-hand' - I don't have a CVS account.... (yet?)

Patch to date_views.inc:

$operator = array(
'=' => t('is equal to'),
'<>' => t('is not equal to'),
'>' => t('greater than'),
'>=' => t('greater than or equal to'),
'<' => t('less than'),
'<=' => t('less than or equal to'),
+ 'IS' => t('is not defined'),
+ 'IS NOT' => t('is defined'),
);

function _date_views_filter_handler($op, $filter, $filterinfo, &$query, $field_type = 'iso') {
include_once(drupal_get_path('module', 'date_api') .'/date.inc');

+ if (strncmp($filter['operator'],'IS',2)==0) { // J. Fall added to filter out null dates
+ views_handler_filter_null($op, $filter, $filterinfo, $query);
+ }

$value = $filter['value'];

Comments

fadeevbiz’s picture

Hello, jfall,
Can you explain how to use this patch. Step by step. I don't understand it completely.
And it seems that readers of branch http://drupal.org/node/101050 don't understand it either.
Can it also be used on DATE 5.x-2 ??

Thank you very much!

fadeevbiz’s picture

It worked!
But when I expose filter to user and filter nodes with DEFINED or UNDEFINED fields it gives Mysql Query error!!! ((((

jfall’s picture

Sorry fadeevbiz - missed a return statement.
Revised "patch":

function _date_views_filter_handler($op, $filter, $filterinfo, &$query, $field_type = 'iso') {
include_once(drupal_get_path('module', 'date_api') .'/date.inc');

+ if (strncmp($filter['operator'],'IS',2)==0) {
+   views_handler_filter_null($op, $filter, $filterinfo, $query);
+   return;
+ }

$value = $filter['value'];

Note to others - to apply this 'patch' by hand, you need to add the lines marked with a + to the location shown in date_views.inc - this is otherwise known as hacking the module and is generally not recommended! This fixed a specific issue for me while I wait for a more general solution being discussed at http://drupal.org/node/101050 (all of whom know much better than I how to fix this, I assure you!)

I'm hoping someone who knows these modules better than I do will review this pseudo-patch. I am fairly new to Drupal, so I don't even really know all the cases to test for. In any case, let us know if this resolved the issue with exposed filters.

karens’s picture

Status: Active » Closed (won't fix)

I'm not making changes to the 5.1 version. I'm officially recommending you move to the 5.2 version now. If you have problems in that version you can check for existing issues or add new ones. Feature requests are now getting posted to the D6 version to be back-ported to 5.2.

I don't know if this still applies in 5.2, so if it does you can create a 5.2 issue.