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.
I got an error ”Invalid argument for foreach on entity.inc, line 199” when my import tried to throw a FieldValidationException with the following $e->error content:
array(1) {
["default"]=>
array(1) {
[0]=>
array(2) {
["error"]=>
string(17) "og_invalid_entity"
["message"]=>
string(46) "The referenced group (node: 34049) is invalid."
}
}
}
It seems that the error handling in plugins/destinations/entity.inc assumes that there are a few more nested arrays in the content. The FieldValidationException definition seems to suggest that the value I got is in correct form:
15 * Constructor for FieldValidationException.
16 *
17 * @param $errors
18 * An array of field validation errors, keyed by field name and
19 * delta that contains two keys:
20 * - 'error': A machine-readable error code string, prefixed by
21 * the field module name. A field widget may use this code to decide
22 * how to report the error.
23 * - 'message': A human-readable error message such as to be
24 * passed to form_error() for the appropriate form element.
Comment | File | Size | Author |
---|---|---|---|
#2 | 2811321-2-FieldValidationException_handling.patch | 1.17 KB | ZeiP |
|
Comments
Comment #2
ZeiP CreditAttribution: ZeiP at Citrus Solutions Oy for City of Turku commentedAttached is a patch with which the error is properly handled. I couldn't find anywhere else (in the module) that the exception should be raised, so I wonder if this is the correct solution or if there's a need for the extra nested arrays in some context.
Comment #3
ZeiP CreditAttribution: ZeiP at Citrus Solutions Oy for City of Turku commentedComment #4
dltj CreditAttribution: dltj at Cherry Hill Company commentedThis patch fixed the same problem that I had (”Invalid argument for foreach on entity.inc, line 199”), and my migration into an existing OG now works. This issue's title says, though, that the problem occurs when importing a faulty OG. As far as I know, my Organic Group is fine; does the fact that this error was occurring mean that this is a problem with my Organic Group setup?
Comment #5
r-mo CreditAttribution: r-mo at CTI Digital commentedThis patch fixes errors within the catch for field cardinality too. $e->errors in this case:
Comment #6
brockfanning CreditAttribution: brockfanning commentedThis patch worked for me as well. Thank you!
Comment #7
Grayside CreditAttribution: Grayside at Phase2 commentedI am encountering the same situation as @dltj in #10: This patch is fixing import of the og reference field. The migrate messages now record the validation error, even though the content seems to be successfully associated with the group entity (in this case a taxonomy term) without a problem.
Given that potentially invalid validation errors are out of scope, this patch seems RTBC to me.
Comment #9
pifagorDone
Comment #10
pifagor