Drupal6
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);
?><?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'));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.






