Display Views result only when exposed filters are set

1 Comments
Appnovation put a small Views tutorial online today, which hides the results of a View with exposed filters on initial display, when no filter value is set. However, the shown approach has a small performance backdraw: it hooks into the view to discard the result after querying the database. A code snippet on drupal.org avoids this by adding an impossible condition to the query, however it requires the use of a dummy argument and – worse – PHP to be executed in Views' argument handler.

Here's how to do it avoiding above pitfalls (put in custom.module):
/**
 * Implementation of hook_views_query_alter().
 */
function custom_views_query_alter(&$view, &$query) {
  if ($view->name == 'My_View' && $view->current_display == 'page') {
    // Don't display results until at least one exposed filter has a value set.
    $filter_set = FALSE;
    foreach ($view->filter as $filter) {
      // Check if we've found a filter identifier that is set.
      if ($filter->options['exposed'] && array_key_exists($filter->options['expose']['identifier'], $_GET)) {
        $filter_set = TRUE;
        break;
      }
    }
  
    // If the filter isn't set, add a WHERE clause to the query that
    // cannot be TRUE. This ensures the view returns no results.
    if (!$filter_set) {
      $query->add_where(0, 'FALSE');
      // To display a different message (or no message at all) you
      // also might want to adjust the Views' empty text. 
      //$view->display_handler->options['empty'] = '';
    }
  }
}

Drupal Pathauto: Bilingual stop word list

0 Comments
I've taken some time to update the stop-word lists for the pathauto module.

English (slightly modified module defaults):
a,an,and,as,at,but,by,for,from,is,in,into,like,of,on,onto,
or,now,per,than,the,this,that,to,up,via,with


German (requires transliteration module to properly convert diacritic marks (Umlaute)):
ab,aber,als,an,auf,bei,bis,der,die,das,den,dem,des,dies,durch,
ein,eine,einer,eines,fuer,ist,im,in,jetzt,mit,noch,oder,
per,sich,um,und,via,von,vom,zu,zum,zur


Hint: since pathauto is currently not language-agnostic, you need to copy both lists into the configuration field ("Strings to Remove").

Drupal should be embeddable

1 Comments
Drupal 6 is currently not easily embeddable into third-party PHP applications, since bootstrapping alters the environment. Needless to say this is bad bad bad. Here's a fairly comprehensive list of modifications applied (in order of execution):
  • during DRUPAL_BOOTSTRAP_CONFIGURATION:
    • drupal_unset_globals() modifies global variables
    • conf_init() changes the session name
  • during DRUPAL_BOOTSTRAP_SESSION:
    • modifies the session handlers and starts a session
  • during DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE:
    • drupal_page_header() outputs headers
  • during DRUPAL_BOOTSTRAP_FULL:
    • _drupal_bootstrap_full() modifies the error handler, sets a new system locale, and strips slashes from request variables.
To resolve these issues, the integrating code should have the possibility to set a flag that tells Drupal to bootstrap without altering the existing environment.

Drupal Admin Menu: Move out developer functions

0 Comments
Currently, Admin Menu has all those neat little helper functions like Clear cache and Disable developer modules built into the core module. To speed up future development, however, it would be great to have them separated into a dependent sub-module, which could then be developed at individual speed.

Along with my former idea of a site switcher module, this could also include more settings for existing functionality, like the Disable developer modules function, which could expose a list of modules and allow the admin to select which ones to disable, instead of just relying on a hard-coded built-in list.

The following existing functionality could be easily moved into its own submodule, in favor of a slimmer main module:
  • Switch user
  • Devel functions
  • Disable developer modules

-moz-transform on table headers

1 Comments
While working on a new feature for DrupalvB, a Drupal module that integrates the vBulletin forum software with the Drupal CMS, I had to create a rather large matrix table allowing to map Drupal roles to vBulletin user groups. Because the group titles in the table header took up most of the space, I decided to test drive an upcoming CSS3 feature in Firefox 3.5: -moz-transform: rotate(). Here's what the result looked like:

Note: the bad font rendering quality isn't the fault of Firefox, rather it comes from using an old version of Microsoft's Terminal Server which doesn't support anti-aliasing.


Unfortunately, rotating elements just cuts the element out of its current position and draws it with the transformation applied, but doesn't touch the reserved space of the untransformed element. This lets the rotated text paint over adjacent DOM elements. However, since the length of the text is dynamic and thus not known in advance, trying to avoid this would need dynamic calculation of the required padding.