HCG Web Services Documentation
6 July 2009 • Version 1.0

Integrating with Drupal

Before using this tag in a Drupal site, you may want to consider using one of the available Drupal modules that integrate with a Google Search Appliance (GSA):

NOTE: At this time, the Integration with Drupal using the remote tag is untested and there may be problems making it work. Both the Google Mini and Drupal use the q variable as a fundamental way of controlling their activity, so a conflict is likely.

 

If you choose to go with the remote tag, integrating it into a Drupal site is fairly simple, but it does require a different approach than the main one described. There are three steps to creating a Google search page in Drupal:

  1. Create a new page where the remote tag can live.
  2. Install the CSS and Javascript files into your theme so they are available when needed.
  3. Set up a URL rewrite to hide Google's q variable from Drupal.

Creating your page in Drupal

Drupal has an integrated search feature which has a default URL of /search. You may be able to override that URL by installing the Custom Search module and using that to change the URL, but for simplicity we will use a different path for the new page to avoid the issue.

  1. In your site's Admin section, choose Create content, then choose Page. Type Google Search into the Title field and copy the tag code into the Body field.
  2. Assuming you have the Path module installed (if you don't you probably should), go to the URL path settings section near the bottom of the new page form and type in your link. For this example, I will use google-search.
  3. Save the new page and you are ready for the next step.

Installing the CSS and JavaScript

Find your theme's .info file. If your theme, for instance, is called mytheme, then your info file is probably located at /sites/all/themes/mytheme/mytheme.info or /themes/mytheme/mytheme.info. You will need to add the following lines to that file.

stylesheets[screen, print][] = http://resources.hcgweb.net/rtags/css/search.css
stylesheets[print][] = http://resources.hcgweb.net/rtags/css/search-print.css
stylesheets[handheld][] = http://resources.hcgweb.net/rtags/css/search-handheld.css
conditional-stylesheets[if lte IE 7][screen, print][] = http://resources.hcgweb.net/rtags/css/search-ie.css
conditional-stylesheets[if lte IE 7][print][] = http://resources.hcgweb.net/rtags/css/search-print-ie.css
conditional-stylesheets[if IE 7][screen, print][] = http://resources.hcgweb.net/rtags/css/search-ie7.css
scripts[] = http://resources.hcgweb.net/rtags/js/search.js

NOTE: if you end up copying these style sheets to your local theme, you can put them into a subfolder if you want to keep them organized. More information.

Setting up the redirect

Open the /.htaccess file in a text editor and add a line above the main redirect block that rewrites the SES URLs to the kind needed by Drupal:

RewriteRule (.*)search.html(.*) /google-search$2 [R]

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]