Zardoz

A Blog

Archive for the ‘Drupal’ Category

A compound field example for CCK 2 & Drupal 6

without comments

For anyone attempting to create a compound field (meaning a single CCK field that is made up of multiple sub-fields) in Drupal, but are lost in a sea of poorly documented hooks and functions so abstracted as to have lost nearly all meaning, like I was for the last two days, I offer you the following example module. This is tested to work on an Acquia Drupal 6.14 build with CCK version 6.x-2.5. By “work”, I mean that your form will have a compound field that saves data and is available in your $node object. There are no settings, no validation or sanitizing or views integration. This is provided merely as a starting point for your own custom module.

For your own use, you’ll want to start with these four functions:

  • compoundfield_field_settings to declare your database structure;
  • compoundfield_process to declare the Form API structure (as you would any other Drupal form);
  • theme_compoundfield to theme the form HTML;
  • and theme_compoundfield_formatter_default to theme the frontend HTML.

Suggestions, questions, and comments are all welcome. This code is mostly a combination of the link module, Karen Stevenson’s very helpful Lullabot article, and this article by Jennifer Hodgdon.

Download: compoundfield 6.x-1.1

Written by Andrew

November 9, 2009 at 3:21 pm

Posted in Drupal

Tagged with , ,

Minimizing TCP connections: Drupal’s Lightbox2 module

without comments

I’ve been trying to cut down on TCP connections per pageview for a Drupal 5 site which uses the Lightbox2 module. I noticed that the following images are loaded, even if none of the images on the page are lightboxed:

/sites/all/modules/lightbox2/images/loading.gif
/sites/all/modules/lightbox2/images/blank.gif
/sites/all/modules/lightbox2/images/prev.gif
/sites/all/modules/lightbox2/images/next.gif
/sites/all/modules/lightbox2/images/close.gif
/sites/all/modules/lightbox2/images/expand.gif
/sites/all/modules/lightbox2/images/pause.gif
/sites/all/modules/lightbox2/images/contract.gif
/sites/all/modules/lightbox2/images/play.gif

It’s possible that Firefox and IE (and/or Safari) behave differently in this case, where an image is called by the CSS background property but the containing element is set to display: none. I don’t see these as loaded in Firebug, but I do see them in “Page Info”, under Media, as well as in the HTTP access log.

Since I’m only using the loading.gif image for preloading (clicking the image itself or the overlay closes the lightbox), I want to keep from loading the rest. The solution here is to comment out the background property definitions in the lightbox2/css/lightbox.css file that call the remaining images. Having done that, the TCP connections needed for each non-cached pageview is reduced by 8.

Written by Andrew

July 29, 2008 at 5:05 am

Posted in Drupal, browsers