Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Drupal: Finding nodes through autocomplete

Parent Feed: 

The clients wanted a quick way to jump to the latest revision of a node. I was delighted to discover that the Finder module made it easy to create an autocomplete shortcut to nodes and users. It offered way more features than I would’ve coded myself. Finder lets you match nodes on title, author, CCK fields, and so on.

There’s a simpler module called Node Quick Find, but I’m going to go with Finder for now because of the options that Finder offers.

There was one small thing I needed to tweak. Finder Node goes to node/nid, but we’ve got Revisioning set up to view the current revision of a node and not the latest. Fortunately, Finder took that into account and provided enough hooks to let me change the behavior. Here’s what I needed to do:

function mymodule_finder_goto_alter(&$result, &$finder) {
  $finder->base_handler['#module'] = 'mymodule';
}

function mymodule_finder_goto($finder, $result) {
  $vid = revisioning_get_latest_revision_id($result->nid);
  drupal_goto('node/' . $result->nid . '/revisions/' . $vid . '/view');
}

You’ll want to use more if logic if you’re working with different kinds of Finders, of course, but this was enough to handle what I needed. Hooray for hooks!

Finder doesn’t seem to support Features, so I’ll need to configure things again once I move to production. No problem! I’ve added some notes to myself in the issue-tracking system we’re using, and I’ve asked the clients to try this new shortcut out.

Drupal: There’s a module for that.

2011-09-02 Fri 14:17

Author: 
RSS Tags: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web