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

This snippet will be helpful in my migration. For some reasons i need to overwrite/update taxonomy term in my migration.

Add new comment

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

Limited HTML

  • Allowed HTML tags: <a href hreflang> <p> <span> <br> <br /> <ul type> <ol start type> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <del> <ins> <sub> <sup> <quote> <blockquote cite> <pre> <code>