Drupal: Finding nodes through autocomplete
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
The post Drupal: Finding nodes through autocomplete appeared first on sacha chua :: living an awesome life.