Converting node refrences to same node type to entity references

Created on 16 July 2013, over 11 years ago
Updated 28 November 2023, about 1 year ago

My use case is this:
I have a D5 to D7 migration. I'm migrating D5 node references to D7 entity references. The twist is that the node references are references to other nodes of the same type (parents). The content type is 'location' and the node reference field is 'field_location_parent'. 'field_location_parent' is also the name of the D7 entity reference field.

Here is the relevant code:
In migration constructor:

$this->addFieldMapping('field_location_parent','field_location_parent')
      ->sourceMigration($this->getMachineName()); // reference to another location

here is createStub()

  protected function createStub(Migration $migration, array $source_id) {
    $node = new stdClass();
    $node->title = t('Stub for @id', array('@id' => $source_id[0]));
    $node->body = t('Stub body');
    $node->type = $this->destination->getBundle();
    $node->uid = 1;
    $node->status = 0;
    node_save($node);
    if (isset($node->nid)) {
      return array($node->nid);
    }
    else {
      return FALSE;
    }
  }

When I add thecreateStub() code above copied from Chickens and eggs to the migration class, I get a fatal error.
Stacktrace attached.
What am I missing?

💬 Support request
Status

Fixed

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024