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.
While updating entities during batch operation (add new field values) the following error occurs:
TypeError: method_exists(): Argument #1 ($object_or_class) must be of type object|string, null given in method_exists() (line 512 of /modules/contrib/field_collection/field_collection.module).
Comment | File | Size | Author |
---|---|---|---|
#7 | field_collection-typeerror_method_exists_PHP8-3285573-7.patch | 672 bytes | nedjo |
Comments
Comment #2
Natallia CreditAttribution: Natallia commentedComment #3
Natallia CreditAttribution: Natallia commentedComment #4
ram4nd CreditAttribution: ram4nd as a volunteer commentedComment #5
ram4nd CreditAttribution: ram4nd as a volunteer commentedComment #6
Steven Jones CreditAttribution: Steven Jones at ComputerMinds commentedHere's a patch suitable for using with -p1
Comment #7
nedjoThanks for noting the error and for contributing the proposed fix.
The error in
field_collection_field_update()
(an implementation of hook_field_update()) indicates the$top_host
variable is, at some point, assigned aNULL
value.The current patch silently accepts a (presumably, invalid?)
NULL
value for$top_host
. That may disguise a problem. It would be preferable to track down and address the source of thatNULL
value.There are two points where
$top_host
is assigned a value. First, it's seeded with the value passed in by the code invoking the hook:$top_host = $host_entity;
. Second, it's conditionally reset to the return value of a::hostEntity()
method call:While it's possible the first assignment is the source of this bug - that is, the hook is being invoked with broken data- that seems less likely on the face of it. That leaves the possibility that the
::hostEntity()
method method is returning aNULL
value. And, indeed, the return value ofFieldCollectionItemEntity::hostEntity()
is only conditionally an entity, and otherwiseNULL
.On that basis, the correct fix here would seem to be to reassign the value of
$top_host
only if the::hostEntity()
call has returned a non-NULL value.Patch attached. No interdiff as this does not continue from the prior patch.
Comment #8
emerham CreditAttribution: emerham as a volunteer commentedRan into this problem when updating a single node that used paragraphs with field collections. Was unable to find the issue but this patch solved the problem.
Comment #9
init90WOrks for me.