drupal 6

Drupal.behaviors: The Two Step Secret To Unlocking Drupal's Javascript

10.12.2008

The hardest part about using drupal's javascript features is knowing where to begin: they remained an arcane mystery to me until today. After drinking a bit of whiskey, and studying how core was using Drupal.behavior, I learned it couldn't be simpler. If you don't know how to do this, take a moment:

Step 1: Invoke the javascript "hook": Drupal.Behaviors.$hook

hook_theme and tpl.php files: registering them with drupal, and passing variables

10.10.2008

There is one way to let drupal know about a theme function or template. There are two ways to send variables to a template, but one of them has a lot of disadvantages.

We'll use two theme functions, with an identical template setup to illustrate these methods:

Creating Theme Functions and Routing Them to a Template

There's only one way, hook_theme()

Loading a Menu, and Theming the Links in Two Lines of Code

10.10.2008

When creating a menu [ admin/build/menu/add ] there's a field for "Menu name". We use that value to load whatever array of menu links we want. In this example, we're using "secondary-links" which comes default on most drupal installs.

<?php

  $menu = menu_navigation_links("secondary-links");
  return
theme('links', $menu);
?>

Discussion

This is a particularly nice technique to use along with hook_preprocessor_page. You can easily send your menu links to your page.tpl.php file from a module like this:

The Drupal Hacker's Cookbook

10.10.2008

This is a guide for hackers -- php developers who are looking for small solutions to big problems. This is not a resource written for programming noobs, though programming noobs are encouraged to use it and learn from it. The format is to the point: a problem, a function, and how this function is used as a solution. We'll only cover drupal 6 and beyond.

Expect this guide to grow day by day.

Drupal 6 AHAH forms: Making New Fields Work

03.28.2008

Today, I was working with drupal 6's AHAH form elements. Initially, I was delighted at how well they worked. That delight turned to confusion once I realized that the form elements I had put in the menu callback of the #ahah['path'] was missing its name attribute. After doing a bit of research in how the poll module handled the formapi voodoo, I created a generalized function to aid in building AHAH callbacks. If there is a better way to do this, I wasn't able to find it. <?php

Syndicate content