Planet Drupal

Drupal File Upgrade Bash Script

Replacing files during a Drupal upgrade can be tedious, especially for those of us who have to worry about SVN files in every directory. The following script automates this part of the Drupal upgrade, making it much faster and less error prone. I've been using the script in its current form for almost a year and it has served me well. And though most of my other bash scripts have been replaced by Drush commands, this script has proven better suited to my workflow than its Drush equivalent.

Overview

The script does the following:

  1. Deletes the current Drupal distribution files while preserving:
    • directories
    • SVN files
    • all files in the /sites directory tree
    • all files in /files directory tree
      (I have a number of sites using the old file directory location)
    • the Komodo (.kpf) project file
  2. Downloads and expands the Drupal distribution tarball if it has not already been done
  3. Copies the new Drupal distribution files to the target directory
  4. Removes the unrequired text files. e.g., CHANGELOG.txt, INSTALL.mysql.txt

Creating and Updating Nodes Programmatically in Drupal 7

The 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.

Filter Format

The format of the text field filter is now specified by machine name, not integer. For example: full_html, filtered_html, or plain_text. This is great news for moving contents between different Drupal systems.

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

Blocks 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:

The Examples for Developers Module

An 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.

Drupal Command Line Scripts with Drush

Drupal'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.

Node Image Gallery with ImageField

ExampleWhen 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

Komodo LogoFinding 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.

Book Review: Drupal 6 Content Administration

Drupal 6 Content AdministrationAnyone 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.

Drupal 7 APIs: A Mindset Change for Scalability

In a presentation at the September 2009 meeting of the Vancouver League of Drupaliers (Vancouver's Drupal user group) core Drupal Developer and Now Public Development Team Lead Károly "CHX" Négyesi spoke about the importance of APIs in Drupal 7. If you're serious about scalability APIs are no longer an optional convenience. For some this may not be an issue, for others this could be a mindset change. Károly also discussed some other Drupal 7 improvements like functional testing.

This is a video of his presentation.

Vancouver Mozilla Service Week (2009)

Last week was Mozilla Service Week and local Mozilla Messaging Technical Support Lead Roland Tanglao organized a Vancouver event at the offices of Agentic. At this point many Drupalistas are probably thinking: Wait a minute, is this the same Roland who used to work at Bryght? Yes, yes it is. And Vancouver readers are probably thinking: Wait a minute, Mozilla has an office in Vancouver? Yes, yes they do.

Pages

Subscribe to RSS - Planet Drupal