Migrating a CCK Field into the Node Title Field

On a recent migration project I came across an odd error:

Illegal offset type in isset or empty File ...snip...\sites\all\modules\pathauto\pathauto.inc, line 182

I was using Migrate 2.5 to move date from a Drupal 6 project into Drupal 7 and had already migrated several content types without having problems with my pathauto settings.

After digging for a bit, I realized that pathauto was being passed an array for the node title causing problems with checking the cache for a previous calculated pathauto URL. Odd, node titles are always strings. Then I realized that this is the first content type that I was pulling the node title from a CCK text field and Migrate will pass that along as an array (just like all other CCK fields).

The fix is easy enough, add a prepare routine to your migration object such as this:

public function prepare($entity, stdClass $row) {
  // Because the title field is imported from a CCK field, it shows up as an
  // array. Node titles have to be strings.
  if (is_array($entity->title)) {
    $entity->title = $entity->title[0];
  }
}

And pathauto is happy again!

Permalink

After digging for a bit, I realized that pathauto was being passed an array for the node title causing problems with checking the cache for a previous calculated pathauto URL. Odd, node titles are always strings. Then I realized that this is the first content type that I was pulling the node title from a CCK text field and Migrate will pass that along as an array (just like all other CCK fields).

mangastream

Add new comment

The content of this field is kept private and will not be shown publicly.