Drupal search block

Publié
2011-05-22 19:02
Written by
Eileen - member of the CiviCRM community and Core Team member - about the Core Team

A customer recently asked Fuzion  if the little contact search box in the top left corner could be made available on all their drupal pages and that it link to the contact's Drupal page.

 

Re-using the Civi-search box seemed a bit too difficult but there was a fairly easy solution to this request using existing drupal modules - finder + views (plus features to deploy).

 

Finder module will create an autocomplete box off any view. I created a basic View based on drupal users. After Pete had finished with it it had 3 fields: contact display name - linked to CiviCRM contact, Drupal user name - linked to Drupal contact & drupal email linked to a mail to. It was also filtered to 'Is Primary Email'. It looks like this (filtered to a single record).

 

CiviFinder view

 

Next up I installed Finder module along with finder_views and finder_autocomplete. Finder appears under site building when installed. I chose to add a Views Finder and selected my View.  I selected both to be able to view the Finder as form and as a block. I then went to 'add element' and chose an autocomplete textfield. There is a 'find items by field' box and I chose the same 3 fields as above. In order to reduce the load I chose the drupal email which is in the same table as the drupal username rather than the Civi email. I'll see if I get a request for the CiviCRM email to be used...

Those few steps were enough that my Finder page now looks like the below. It will autocomplete on username, email or CiviCRM display name.

CiviFinder

The block sits on the left hand side & currently looks like this.

 

After a bit of tinkering when it seemed OK I packaged the view into a Feature which can be Fuzion SVN">downloaded & installed from the fuzion svn (accept the certificate - it's self-signed). One of my biggest gripes about the Finder module is that it isn't possible to export finders as a Feature. The maintainer seems fairly opposed for some reason I can't make sense of. Anyway, I did find I could add the Finder module to the install hook on my Feature so it was possible to package it with the view although it's not possible to maintain it in code going forwards like you can with a Feature.

So, to use our implementation - you need a bunch of modules; Views, Features, Finder, CTools. Once you have all of them enabled just enable civifinder and there will be a block available for you to enable wherever you want on your site

Comments

If you wanted to search civicrm contact names and/or email addresses, you could always use the CiviCRM APIv3, as Xavier and I demonstrated with CiviMobile :)

 

This page has a bit of jquery.mobile js cruft in it, but otherwise is a good example of how to add a dynamic CiviCRM contact search into a template:

 

 

https://github.com/kylejaster/CiviMobile/blob/master/templates/civimobile.contact_list.tpl.php

 

 

And there is a crmAutocomplete js I think, so that's even more a one liner than what was done for civiMobile.

(and extra point for Kyle to point out to no less than Eileen that she should have been using the api v3 ;)