Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When I run a migration that uses a field of this type, I get the following warning (an informational message as seen in "migrate" log) ...
Undefined property: stdClass::$nid File nodereference_count.module, line 165
The error is coming because the code doesn't check if the "nid" property is populated - which it isn't in the case of a node that is yet to be saved.
A simple solution is to change the following code ...
function nodereference_count_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
if ($field['type'] == 'nodereference_count' && $entity_type == 'node') {
$items[0]['count'] = nodereference_count_get_count($instance['settings'], $entity->nid);
}
}
to this ...
function nodereference_count_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
if ($field['type'] == 'nodereference_count' && $entity_type == 'node' && !empty($entity->nid) {
$items[0]['count'] = nodereference_count_get_count($instance['settings'], $entity->nid);
}
}
Will be attaching patch ...
Comment | File | Size | Author |
---|---|---|---|
#4 | nodereference_count-nidmissing-2521806-4-7.x.patch | 694 bytes | Jitesh Doshi |
Comments
Comment #1
Jitesh Doshi CreditAttribution: Jitesh Doshi commentedPatch attached ...
Comment #2
John Franklin CreditAttribution: John Franklin commentedis this a duplicate of #1689338: programmatically creating nodes with nodereference count field causes undefined property error?
Comment #3
Chris Charlton@Jitesh, your patch has a typo/bug:
should be...
Comment #4
Jitesh Doshi CreditAttribution: Jitesh Doshi at SpinSpire commented@Chris Charlton, thanks for catching that. I have fixed the bug/typo and attached a new patch. Please use this one.
Comment #5
Chris Charlton