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!
Migrating content between Drupal versions often surfaces errors that only appear after many content types have already been processed, since rare edge cases hide behind seemingly ordinary data shapes. When automated routines treat titles as plain strings by default, a single unexpected array value can break internal assumptions about cache lookups and path generation patterns. The behaviour tends to coincide with fields originally created through older contributed frameworks, where data may have been combined, duplicated, or restructured before the modern content model took shape. Reviewing how each field is mapped before running a large import helps prevent silent failures that only emerge midstream when a less common value is finally encountered. Tracing the original structure rather than trusting surface appearance keeps migrations reliable across long-running sites.
Thanks for sharing
Post new comment