Testing the world of code!
Check it out! I've added code formatting to Thinkyhead with the Code Prettify module, so now I can blog incessantly on interesting (to me) code topics! I have all kinds of things I can't wait to share. Tricks of the trade, examples of simple things you can do to make your sites and apps better, and of course my own conundrums as I venture into the world of C# and Unity3D!
Without any further ado, here's a piece of script from the FancyZoom Drupal module to get us started:
function _fancyzoom_script_path() { $paths = array(drupal_get_path('module', 'fancyzoom') .'/fancyzoom'); if (function_exists('libraries_get_path')) { $paths[] = libraries_get_path('fancyzoom'); } foreach ($paths as $path) { if (file_exists("$path/js/standard/FancyZoom.js")) { return $path; } } return FALSE; }
A note on style: I always start utility functions in my modules with an underscore. Some modules follow this style while others don't. The idea is that if a hook should be created by some module in the future that matches the name of your function, the underscore will prevent your function from being mistaken as a hook and called at weird times with weird arguments.
With that out of the way, what's so cool about this utility function? It's only a function that every Drupal 5 / 6 / 7 library glue module should include, that's all! It looks for some library in a list of folders. It looks first in the current module folder, then if there is a properly-named folder anywhere in the paths provided by the Libraries module it looks into those.
I mentioned that Drupal 5 modules should look for libraries_get_path, even though no libraries module exists for Drupal 5. Even though that is the case, developers have found it very easy to port libraries to Drupal 5, and I recommend having it on your Drupal 5 sites, if you still have any hanging around. (I have one out there that's still going! But mostly I use Drupal 5 on my laptop and just keep it alive there.)
- More by Thinkyhead
- Login to post comments