Creating and Updating Nodes Programmatically in Drupal 7
Submitted by dale on August 31, 2010 - 6:52pmThe steps for programmatically creating a node are:
- Create a PHP object representing the node data
- Save the object using the node_save() function
While the mechanics are simple, there is an important responsibility involved. The Drupal work flow does data validation before calling the node_save() function; node_save() does no validation. By calling node_save() directly your code takes the responsibility for providing valid data.
Drupal 7 Changes
A quick note for those of you familiar with Drupal 6. You'll notice two changes in Drupal 7:
Body Field Is No Longer Special
In Drupal 6 the body field was special. Specifically, it had a different data structure than other fields and it always existed, even if it wasn't used. With Drupal 7 the body field is a standard field provided by core and is truly optional.
Language
Language specification is required for the node and some fields.
Basic Node Creation
The following code assumes an unchanged Drupal 7 Standard installation and will create a Drupal 7 article node.
Drupal 7 Blocks: What's Changed Under the Covers
Submitted by dale on August 17, 2010 - 12:14pmBlocks in Drupal 6 (and 5) always felt a little less loved than other portions of Drupal. While the node and theming APIs offered straightforward and often elegant methods to modify behaviour without modifying other peoples' code, blocks weren't so fortunate. Lacking API support, working with blocks often meant writing ugly code. Last week helping with the Drupal Block API documentation I discovered this has changed in Drupal 7. I thought I'd share what I learned.
The information I'll discuss is a summary of the block information from:
- Converting 6.x modules to 7.x (http://drupal.org/node/224333)
- Converting 6.x modules to 7.x - Categorical (http://drupal.org/node/394070)
- Block API Documentation: block.api.php
- Examples Module: block_examples.module (From: Examples for Developers project)
The Examples for Developers Module
Submitted by dale on July 30, 2010 - 2:21pmAn example, like a picture, is worth 1000 words. Until recently Drupal programming examples existed but were spread among documentation pages, blog posts, and the Drupal CVS repository; some searching required. That changed in late 2009 with the introduction of the Examples for Developers module. Its purpose: "to provide high-quality, well-documented API examples for a broad range of Drupal core functionality". Now you can find high-quality, working Drupal 6 and 7 code examples in one place, many with SimpleTests.
The Examples for Developers Module, or simply Examples Module, is actually a collection of modules. Each sub-module contains a single, specific example of how to use an API or implement a feature. At the time of writing there are 17 examples:
Drupal Command Line Scripts with Drush
Submitted by dale on July 23, 2010 - 7:16amDrupal's scripting abilities just keep getting better and better. Since publishing my Drupal Command Line Script Template last year I've moved exclusively to the Drush php-script (scr) command. The script template article still gets a lot of page views - perhaps because with all the functionality in Drush it's easy to miss the scripting feature - so posting an update seems like a good idea.
Drush Scripting Advantages/Disadvantages
The advantages of using Drush over using my original template are:
- Drush takes care of creating the Drupal environment for the script to run in, which is the only function the template served. Using Drush factors out the environment common code, eliminating redundant code in individual scripts.
- Drush makes it easy to place the script files in a directory outside of the Drupal website home directory. Placing script files outside the website home directory eliminates a whole range of security issues.
- The Drush code that creates the Drupal environment is reviewed by the community, making it far more robust than something a single person could create or maintain on their own.
- When the code required to create the Drupal environment changes you don't need to update individual templates, just Drush.
Riese: From Bytes to Broadcast
Submitted by dale on July 8, 2010 - 1:05pmIn May I attended Melting Silos Case Study – Riese: From Bytes to Broadcast, a talk in the What’s Going On Salon series. From the talk description:
Join Riese series creators Kaleena Kiff and Ryan Copple as they share their combined learned experiences in navigating the constantly shifting landscape of new media in taking their Vancouver based web series production mainstream. Among their unique insights are models of remaining adaptable as the landscape shifts, strategies for harnessing a fan base and planning ahead for the jump to mainstream media. They will showcase their multiplatform property including examples of their ARG and their iPhone game app.
Kaleena Kiff is no stranger to television production. She worked as a child actor in California and after getting her BA from McGill moved behind the camera (though she does have bit-part credits on Supernatural and Smallville). Ryan Copple graduated with a Masters of Forensic Psychology in Nebraska then moved to Vancouver to pursue a film career. Their presentation was a rapid fire staccato of detail organized into topic areas. Unlike so many presentations, the detail was imbued with their personality and experience, making for both an entertaining and informative session.

Kiff started by pointing out these are still early days for Riese. Though progress is excellent, the presentation was framed as success to date, not the final summary. Here, with no specific narrative, are my notes from the presentation:
Designing in a Cross-Cultural Context: Lessons Learned
Submitted by dale on June 30, 2010 - 12:49pm
Have you ever been asked to do something only to discover it's not the best way to deal with the situation? Throw in a language barrier and you have the situation Kara Pecknold found herself in in early 2008. As part of her thesis project she took an internship to develop a website for a Rwandan weavers cooperative. After observing the situation firsthand she experienced a mind shift. In her presentation: Designing in a Cross-Cultural Context: Lessons Learned, given to the Vancouver User Experience (VanUE) group on March 16, 2010, Pecknold told the story.
The Covaga is a women's weaving cooperative in Rwanda that extracts weaving fibre from the water hyacinth and turns it into a product. The water hyacinth is an invasive species, so its harvesting and subsequent use as weaving fibre serves a dual useful purpose. The goal of Pecknold's internship was to design a website to facilitate the sales of these woven goods to the world.
Node Image Gallery with ImageField
Submitted by dale on June 23, 2010 - 8:57am
When image-sets are discussed it's usually in the context of a full featured photo gallery, but there's another common use: including a set of images with the content of a node. For example, product images with a product node or a "mini" photo album with an article. The CCK ImageField combined with a jQuery module like Thickbox makes adding image-sets to nodes easy. Here's how.
Overview
This "recipe" describes how to add a gallery style photo-set to a node. This photo-set stands apart from the node content as a set of thumbnails which can be clicked on to display the full-size version. The Thickbox slide-show feature is also implemented so viewers are able to step through the full-size version of the pictures without exiting the viewer. Although Thickbox is used, this technique should be easily adoptable to different plug-ins.
An example of the technique can be seen here: Finding the Blue Whale
Rocking Development with Komodo Edit
Submitted by dale on December 2, 2009 - 10:52am
Finding the time to really learn the tools we use can be difficult, but sometimes opportunity breaks the door down. This was the case at the Pacific Northwest Drupal Summit with Jeff Griffith's presentation Hacking Komodo for Drupal Development. In his presentation Jeff presented a buffet of features that can make you faster in Komodo Edit (and in most cases, the Komodo IDE). Jeff made his presentation slides available and there's a full video of his presentation at the PNWDS site: Hacking Komodo for Drupal development.
Here are some quick notes from Jeff's presentation. They don't cover everything, but do include things like enabling jQuery autocomplete, handy extensions you can install, and running command line scripts from inside Komodo.
Configuration
Make sure you have PHP configured, or you won't get PHP autocomplete

Create a Komodo project file in your top level Drupal directory to get autocomplete on Drupal functions OR Add the Drupal system directories using the library includes feature.
If you're using jQuery, you can enable jQuery function autocomplete using the API Catalogs jQuery Javascript library.

Book Review: Drupal 6 Content Administration
Submitted by dale on November 24, 2009 - 8:35am
Anyone who's tried to explain Drupal's content feature-set to the uninitiated appreciates the amount of territory that needs covering as well as the challenges inherent in presentation depth and order. J. Ayen Green takes up the challenge in his book, Drupal 6 Content Administration, published by Packt Publishing. Packt graciously provided me a copy for review.
The stated purpose of Drupal 6 Content Administration is "a quick-start guide that best serves Drupal Content Editors." Green is serious about the audience and serious about the content focus. The discussion and examples are firmly rooted on content and live in the user interface, using language targeted to the audience; except for the appendix, there are no digressions into unrelated topics like site administration, SEO, or account management.
The book's content falls into three broad categories: authoring/formatting content, methods for displaying content, and managing content. Each subject has a short introduction and explanation, and almost all include an example of something that can be implemented with step-by-step instructions for doing so. Green has made an interesting decision, the step-by-step instructions assume the Drupal site has already been configured and he does not digress into a discussion on configuring the modules required for the example.
MacBook Pro FireWire 400 / 800 Conversion
Submitted by dale on November 17, 2009 - 3:14pmGetting the latest greatest piece of personal electronics is mostly a happy occasion, but there can be "moments". I recently replaced my circa 2003 MacBook Pro with the current MacBook hotness, which included a switch-up from FireWire 400 to FireWire 800. But wait, my mini-DV camera is FireWire 400; will my old camera talk to my new MacBook? The joy of playing with iMovie 2009 was tempered by the thought I might not have any footage to edit.
Information on connecting FireWire 400 devices to Apple MacBook Pros with FireWire 800 is promising but not definitive (this may change for the better by the time you read this post). A number of forum posts indicated that all that was required is the appropriate adaptor or cable. Having been burned by assumptions I proceeded with the expectation it would probably, but not necessarily, work. Fortunately, it worked!

For those of you in a similar situation I can vouch from personal experience that a Canon ZR800 mini-DV video camera with FireWire works fine with a MacBook Pro FireWire 800 connection. I found two possible solutions: a $14 connector that allowed my existing cable to connect to my MacBook, and a $35 cable that would connect my camera directly to my MacBook. Since I already had a FireWire 400 cable I opted for the connector. At the time of writing I've taken around 15 hours of taped video off my camera without any problems. I've also successfully live streamed via UStream.
