formapi

Never name a theme and a module the same thing

Lets say you're building a drupal website for Bill's Widget Company. You create a custom theme, and a custom module. Now lets also say you are as dumb as me, and decided to name both your theme and module the same thing: bwc. Its a small mistake you'd never make if you thought for a second: "Should my module and theme share the same drupal namespace?" It sounds dangerous, even if you don't know why. Here's why it is dangerous:

The first sign of trouble happened as soon as I added an implementation of hook_form() "bwc_form" to bwc.module. Not only did my form not work, but NO form worked. All forms returned as "array", and frequently had incorrect data types being passed (stdClass's where there should have been an array and vice versa). It was a bit embarrassing how long it took me to figure out the obvious cause:

Since my theme (themes/bwc/bwc.info) shared the same namespace as my module (bwc.module), the theme system mistakenly interpreted bwc_form(&$node) as an override to theme functions: 1. phptemplate_form, and 2). theme_form.

Hopefully, whoever makes this mistake next will find this answer.

Drupal 6 AHAH forms: Making New Fields Work

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