Drupal Tutorials

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

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:

Overriding Menu Page Callbacks

Sometimes you need to override more than a theme function: the entire page needs to be overridden. Drupal 6 makes it rather easy to do this.

In the example below, we call hook_menu_alter(&$callback) to override the display of every single node page view.

Instead of returning a node page, we return "[author's username] is great... for me to poop on.".

 

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

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.

Five Drupal 6 WYSIWYG Editors Reviewed

Tags:

I reviewed 5 WYSIWYG editor modules for drupal 6: FCKEditor, TinyMCE, WYMeditor, jwysiwyg, HTMLBox. The latter three aren't yet mature, so I saved the in depth reviews for the big guys, tinyMCE and FCKeditor. Truth be told, I decided to have low expectations, and rated these modules against the following:

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:

Creating a Template File Via a Form Element

If there is one thing I hate more than breath and martial arts (all kinds...), its writing copy within a php array. So for a recent project that required text-heavy forms, and a bunch of emails, I created an element that mimics php template. The usage and theme function are rather simple: (and rather stolen from phptemplate_render().

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

Drupal CSS Coding Standards

On the #drupal IRC channel, Excallibur points out that there are no coding standards for CSS. I'd like to propose some straightforward ones.

Note that I am not intentionally omitting indentation within rules, but am having trouble with my code filter.

Enabling/Installing New Modules via Update.php: The Complete Solution

In our last episode of enabling new modules via update.php, Steve McKenzie pointed me to a better method: module_enable(). A quick test found, however, that it didn't run the install files, and didn't rebuild the module files cache. So after spending 5 minutes in system.module, I found all the missing pieces. The example update function below will install and enable the new module, as well as rebuild all the css, node type, and menu caches.

Enabling New Modules Via Update.php

UPDATE: There's a better way.

I work with 3 other developers, all of whom have their own local sandbox of our site. Since we're constantly adding new modules, I found a simple way to enable a new module via another module's .install file. That way, all we have to do is run update.php when we update our source tree.

Here's a simple example update function:

<?php

Pages

Subscribe to RSS - Drupal Tutorials