Drupal

Migrating from D6 upload.module to filefield.module

So building on my last post for creating CCK fields, here's some code I whipped up to migrate from the D6's core upload.module to the filefield.module. This isn't general purpose code but might help someone else out. The catch is I'd built a video node with and was using the upload module to attach exactly two files, an image and a video. The new node will have separate thumbnail and video fields. If you'll be moving to a multi-value field this code won't work for you.

The gist is the same as before, setup your field for video and your field for images then export using:

<?php
var_export
(content_fields('field_web_video', 'video'), 1);
?>
and
<?php
var_export
(content_fields('field_video_thumb', 'video'), 1);
?>

Then roll that into an update function that also moves the file data around in the database. Code is after the jump.

Programatically creating a CCK field in Drupal 6

I spent some time today trying to figure out how to create a CCK field as part of an hook_update_N function. Unlike previous versions of CCK, in 6 it's very easy to manipulate the fields from code.

The first step is to create the field using CCK's UI. Once you've got the field setup the way you'd like it use PHP's var_export() to dump the contents of the node's field as an array:

var_export(content_fields('field_translator_note', 'feature'));

Prefilling the ImageCache cache with wget

Today I needed to get Drupal's ImageCache module to regenerate a bunch of resized images. ImageCache doesn't create the images until a browser requests them and at that point the new image is saved to the disk for future use.

One way to generate the images would have been to just click my way through every page on the site but I'm way to lazy for that. So I used wget:

wget -r -nd --delete-after http://example.com

By using the recursive (-r) and --delete-after switches I was able to have it crawl the site and get all the images generated. Bonus points for running in on the server so that the transfers were via the loopback interface so the transfer didn't count against the monthly bandwidth limit.

DrupalCampPDX

drupalcamppdx keynote I took a break today from my work at Sticky building a website for a major sports apparel company that cannot be named, for DrupalCampPDX. Ben Kaplan and I did the keynote presentation this morning which was definitely an honor. I followed that up with a panel on best development practices which was a bit unplanned but went really well. This afternoon I'm doing a presentation on Views2 and Panels2, I'm a little freaked out on that since I've done zero preparation at this point.

Drupal6: Display block for one node type

This is a little snippet I came up with to get a block to show up on a single node type:

<?php
$menu
= menu_get_item();
if (
$menu['path'] == 'node/%' && isset($menu['page_arguments'][0]->type)) {
  return
$menu['page_arguments'][0]->type == 'story';
}
?>

It uses the node type stored in the menu system so you don't have to match arg(0) etc.

DrupalCon Day 1

Made it out to Boston last night. I'd gotten upgraded to business class on the flight from Portland to NYC which was a nice treat. NYC to Boston in coach was a bit of a blow to my ego but the scenery made up for it. The highlight of the flight was looking out the window and seeing a white speck fly by, it was three white balloons. As the sun set we were flying through a beautify pink mist.

I'm staying with a friend of my brother's friends. Great place but it's an hour away from the conference center by train/bus so I was up early this morning. I've got a nice tickle in my throat so I hope I don't end up sick.

Here's the presentations I'm hoping to hit today:

Sorting numeric values stored in character fields with views.module

I spent a good chunk of time this morning trying to figure out how to get the views module to sort a character field with numeric data correctly. The audio module has a normalized table of meta-data meaning that there's one column for the tag name and one for the value. The value is stored as a character string which causes problem when sorting numeric data like the track numbers or years. If you've got a SELECT value FROM audio_metadata ORDER BY value that returns the range of numbers 1...13 it ends up sorted as 1,10,11,12,13,2,3...9. The trick as I discovered is to add zero to the field to coerce it to a numeric value: SELECT value + 0 AS v FROM audio_metadata ORDER BY v.

The problem then is to figure out how to get the views module to generate this bit SQL to get the sorting right. The solution I came upon is when defining the field set 'notafield' to TRUE and provide a 'query_handler' to generate the correct SQL. I've included the relevant parts of the audio module below to demonstrate how it works. You can see the complete code here.

Technical writing

After installing a new hard drive I decided it was time to re-install Windows and clean everything up. I firmly believe that the best time to document something is when you're doing it. So I took the opportunity to write some instructions for setting up a Windows based Drupal development machine. I hope it's of use to someone.

Installing PHP 5 on Windows

This page provides instructions for a Drupal developer who'd like to install PHP 5 on their desktop computer. The instructions assume that you're running a recent version of Windows (NT, 2000, XP, or 2003). Older version like Windows 95, 98 and Me will not be addressed.

Installing MySQL Server on Windows

This page provides instructions for a Drupal developer who'd like to install MySQL 5 on their desktop computer. The instructions assume that you're running a recent version of Windows (NT, 2000, XP, or 2003). Older version like Windows 95, 98 and Me will not be addressed.

Running multiple versions of Drupal on Windows

Once you've been developing Drupal modules for any length of time you find that you need to test code on multiple versions of Drupal. The easiest way to do this is have separate Drupal releases running as virtual hosts. In this guide I'll walk though setting up Apache virtual hosts for Drupal 5 and Drupal HEAD. I'm assuming you're running Windows 2000 or greater and that you've already gotten Apache, MySQL and PHP setup and running on your local machine.

Windows based Drupal Development

With the aim of helping new Drupal developers get setup on Windows, I've created the following guides.

On the Lullabot podcast

I've finally made it into the Drupal gliterati! Robert interviewed me earlier this week for the Lullabot podcast. It's all part of my plan to become a Lullabot when I'm done and graduated. Topics included: Phlickr/Flickr, my Summer of Code project, brewing beer and my stumbling speech.

Summer of Code

I put in two applications for this year's Google Summer of Code. The first was working on programming tools for Squeak and the second was creating a project_metrics module for Drupal. The Squeak proposal was definitely the weaker of the two, there were too many questions I wasn't able to answer to write a good proposal. In contrast, the Drupal proposal practically wrote itself. I've done enough work with Drupal that I already know how 90% of it will work out and I'll have enough time to figure out the other 10%.

I've got it on good authority—lets just say several little birds told me—that my Drupal proposal will be accepted when they announce the results tomorrow. I'm very excited to be in the Summer of Code and very excited to be able to give something back to Drupal.org

Update: it's official, my Drupal proposal has been accepted. I'll be having a Summer of Code.

the quick way to get good drupal support

the best way to get a patch committed Send your developer a 12 pack of local micro brew -- it'll do wonders! Big thanks to mattrock at WSUM, all your station module issues will be marked critical by default from now on ;)

for you, a photo

flower shop

ads

User login

Syndicate content