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:


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.

CommentFileSizeAuthor
views_20070508_is_null_handler.patch1000 bytesmfredrickson

Comments

yched’s picture

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.

mfredrickson’s picture

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.

merlinofchaos’s picture

Status: Needs review » Fixed

Committed to -dev.

Anonymous’s picture

Status: Fixed » Closed (fixed)
liquidcms’s picture

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?.

dawehner’s picture

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