Drupal 7 Upgrade: Ugh, themes.

So, themes. As I mentioned in my previous post, this is one of my big roadblocks in upgrading to Drupal 7.  I have 6 sites that run off of the same Drupal instance, each with its own custom theme (and in many cases, variations on themes within those sites). A conversion guide has been created, but with 53 different things to pay attention to, it's quite the daunting read.  Of course, not everything in that guide applies to me; however, much of it does.

Being ever the optimist, I decided to try dropping my themes into D7 to see what would happen.  Essentially, nothing much.  Unfortunately, by 'nothing much' I mean, 'nothing much works.'  I do get the general structure of the page, but with no content or navigation.  Also, the admin menu appears to be throwing portions of the page content out of alignment.

Broken theme

Fortunately, the admin pages gives me an idea of where the problem is1

Drupal's error reports about the D6 theme

Essentially, the problem is my use of variables to place pieces of content in Drupal combined with a change in the way regions are rendered onto the page. In Drupal 6, regions were rendered like:

<?php print $mission; ?>

In Drupal 7, this has changed to:

<?php print render($page['highlighted']); ?>

Small, but very important difference. I had already started using the D7 way of defining regions in the theme.info file, so wasn't hit by it there.

Another fairly substantial problem I have encountered is that my content-type specific templates no longer work. I had previously used page-contenttype.tpl.php to create specific templates for things like the front page, etc.  These no longer get loaded by Drupal.  It looks like someone might have started documenting a migration of these, but I'll need to take some more time to change the way these are done.

This was fixed relatively easily by adding the following to template.php, and renaming the files from page-contenttype.tpl.php to page--contenttype.tpl.php (e.g., page-front.tpl.php -> page--front.tpl.php).

function srcom_get_suggestions($args, $base, $delimiter = '__') {

// Build a list of suggested theme hooks or body classes in order of
// specificity. One suggestion is made for every element of the current path,
// though numeric elements are not carried to subsequent suggestions. For
// example, for $base='page', http://www.example.com/node/1/edit would result
// in the following suggestions and body classes:
//
// page__node page-node
// page__node__% page-node-%
// page__node__1 page-node-1
// page__node__edit page-node-edit

$suggestions = array();
$prefix = $base;
foreach ($args as $arg) {
// Remove slashes or null per SA-CORE-2009-003 and change - (hyphen) to _
// (underscore).
//
// When we discover templates in @see drupal_find_theme_templates,
// hyphens (-) are converted to underscores (_) before the theme hook
// is registered. We do this because the hyphens used for delimiters
// in hook suggestions cannot be used in the function names of the
// associated preprocess functions. Any page templates designed to be used
// on paths that contain a hyphen are also registered with these hyphens
// converted to underscores so here we must convert any hyphens in path
// arguments to underscores here before fetching theme hook suggestions
// to ensure the templates are appropriately recognized.
$arg = str_replace(array("/", "\\", "\0", '-'), array('', '', '', '_'), $arg);
// The percent acts as a wildcard for numeric arguments since
// asterisks are not valid filename characters on many filesystems.
if (is_numeric($arg)) {
$suggestions[] = $prefix . $delimiter . '%';
}
$suggestions[] = $prefix . $delimiter . $arg;
if (!is_numeric($arg)) {
$prefix .= $delimiter . $arg;
}
}
if (drupal_is_front_page()) {
// Front templates should be based on root only, not prefixed arguments.
$suggestions[] = $base . $delimiter . 'front';
}

return $suggestions;
}

I also discovered that I had to reconfigure many of my blocks after the D7 database upgrade, and reconfigure some of my content types, especially those that made use of the filefield and image content fields.2 This was, however, enough to get me to this state:

Almost there!

From here, I just need to start reconfiguring blocks and content types, and do another pass through the Views.  But I'm already 70% of the way through the migration process, at least in terms of bringing the theme over.

There are still some issues around the admin menu and overlay when logged in as an administrator (or as any user that gets the toolbar) that I'll have to deal with -- but that's really just a matter of some styling.

  • 1. Basically: everything, everywhere
  • 2. The reason for this is that filefield and imagefield were both incorporated into Drupal core in D7. The unfortunate side effect of this was that those content fields and all their content appear to have been lost in the upgrade.