Drupal Content Type Names Limited by Triggers

Published October 13, 2010

Experienced programmers know the many benefits of using descriptive identifiers, such as the names of variables and functions. Descriptive names make it easier for the original developer — and all who follow — to understand the intent of the code, and to make global changes with minimal risk. In Drupal, when creating a new content type, the site developer assigns a human-readable name (which may consist of alphanumeric characters and spaces) and a computer-readable name (which may consist of lowercase letters, numbers, and underscores). Given the usual time pressures of website development, it may be tempting to assign a short computer-readable name. For instance, if the content type is named "Board Member Biography Page", then a lazy programmer might choose "brd_mem_bio_pg" as a terse computer-readable name. But years later, when maintainers are looking through large tables containing content type names, will it be immediately unmistakable to them what the original programmer meant? "Hmm, brd_mem_bio_pg… Bored? Memory? Biology? Pig?!"

At first glance, a wiser choice would be something like "board_member_bio_page", which is far more descriptive. After all, at 21 characters in length, it easily fits within the 32 characters allowed by the node.type field. Unfortunately, if the website will be using workflow triggers, then this longer name will fail, and the reason is not obvious. When the first workflow is added to a site with many roles, and actions are assigned to triggers for the transitions from one workflow state to another, then Drupal will try to assign values such as "workflow-board_member_bio_page-13" to the "op" field in the trigger_assignments table. But that field is also 32 characters long, and thus the value is silently chopped down to "workflow-board_member_bio_page-1". Consequently, all additional actions whose IDs start with the digit "1" are mistakenly assigned to the first one that appears in the table.

In essence, the trigger_assignments.op field is too short for workflow trigger assignments for content names beyond 20 characters, in most cases. When the original developer created that table, the length of 32 probably seemed sufficient, especially as it matches the length of node.type. But the values include trigger type names as prefixes, and transition IDs as suffixes — and thus causes this problem, which has been reported by others

When defining a new content type, be sure to use descriptive names, but watch out for the size limitation imposed by this trigger assignments field. It is best to limit the computer-readable name to 20 characters in length — or even fewer, to be on the safe side.

This DrupalEasy Quicktip is from Michael J. Ross, a freelance Web developer.

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!

Name
CAPTCHA