Download & Extend

Provide a handler for IS NULL/IS NOT NULL

Project:Views
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Views provides a number of useful out of the box handlers (=/!=, LIKE, etc). I didn't see a IS NULL/IS NOT NULL handler.

The following patch provides a new function views_handler_filter_null that allows filters to limit on IS NULL/IS NOT NULL. The operator passed in must be 'IS' or 'IS NOT'.

This patch does not add a operator handler to provide the IS/IS NOT array. An example might look like:

<?php
array('IS NOT' => t('Does'), 'IS' => t('Does not'))
?>

This looks backwards, but it is correct as the completed phrases would be "Does" => IS NOT NULL and "Does not" => IS NULL.

If this patch is accepted, I promise to add a comment to the view developer handbook documenting it, such that it can be easily included in the main documentation.

The usecase for this functionality is the bio.module: filtering based on an author having crated a bio node or not.

AttachmentSize
views_20070508_is_null_handler.patch1000 bytes

Comments

#1

mfredrickson : on a semi-related note, I'd be interestind in having your opinion on http://drupal.org/node/101050 :
'Empty / not empty' filter for CCK fields (or more ?) - relevant comments are #2-#3, #8-#9, #20)

I'm not trying to hijack this thread, though (even if I'm probably spamming it :-) ). +1 on the ready to use handler.

#2

I think the link is topical. I commented in more detail over on that issue, but to paraphrase: this handler would be useful, if all CCK fields standardized on NULL as the empty indicator.

#3

Status:needs review» fixed

Committed to -dev.

#4

Status:fixed» closed (fixed)

#5

Status:closed (fixed)» active

sorry to re-open.. but can someone point me to where this is visible? Is this just adding api that will need to still be coded/patched into other modules to be usable?

I have latest rev of Views and i don't see any way to filter on NULL for an integer field, also not on Title field - perhaps this was just added for Text fields?.

#6

Status:active» closed (fixed)

If you have a class which is a subclass of views_handler_filter_numeric you just have to define "allow empty" in your definitions.

<?php
   
// if the definition allows for the empty operator, add it.
   
if (!empty($this->definition['allow empty'])) {
?>

Please don't reopen OLD issues

nobody click here