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.
Everything was working fine and I didn't spot this until clearing caches.
Fatal error: Call to a member function render() on a non-object in /modules/field_collection/field_collection.views.inc on line 46
It looks like its an issue for me when using a field collection on a custom entity (ECK). My custom entity type is called 'card' and $entity_type->getLabel() returns a string 'Card'.
Comment | File | Size | Author |
---|---|---|---|
#12 | field_collection_eck_label-2717399-12.patch | 682 bytes | imclean |
| |||
#9 | field_collection-eck-2717399-9-8.x-1.x.patch | 1.51 KB | audriusb |
| |||
#3 | field_collection-call-to-member-function-render-2513632-1-8.patch | 684 bytes | lodey |
|
Comments
Comment #2
jmuzz CreditAttribution: jmuzz commentedI haven't run into this and I've been using custom entities for most of my testing.
Can you provide steps to reproduce? If this happens in a view, be sure to include information about how the view is set up.
Comment #3
lodey CreditAttribution: lodey at NDP commentedHi jmuzz,
I have a custom content type with an entity reference field, through this I can add my ECK bundles, inside one type I am using a single field collection field limited to 3 items. Everything worked fine during set up. I'm not using any views.
It looks like in my case line 46 expects an object, and it looks like the ECK entity just passes a string with the bundle type name 'card'.
$args['@entity'] = $entity_type->getLabel()->render();
I haven't spent much time trying to figure out what the code is doing - I literally just tried adding an extra conditional, much like the one on line 47, it just checks if there is an object, if not it passes forwards with the same value.
$args['@entity'] = (is_object($args['@entity'])) ? $entity_type->getLabel()->render() : $args['@entity'];
Patch attached here - I haven't tested this much yet, but it seems to fix my issue fine. I plan to use a few more field collections on this project, so will report back if I get any issues.
Is this something to take across to the ECK project? Any thoughts?
Comment #4
lodey CreditAttribution: lodey at NDP commentedNope - I was way too hasty. That patch just causes other issues for me.
Any advice? I'm happy to put some more time in testing or trying other approaches.
Comment #5
jmuzz CreditAttribution: jmuzz commentedThanks @lodey.
I thought ECK was what they used to call the entity system in Drupal. I didn't realize it was a separate project so for what it's worth I have not actually been using ECK entities.
Comment #6
jmuzz CreditAttribution: jmuzz commentedComment #7
Danny EnglanderI just ran into the same exact error with the same scenario as in #3 above. I am referencing a field collection inside an ECK bundle entity.
Comment #8
audriusb CreditAttribution: audriusb commented#3 patch generates a lot of warnings. I used this line instead to replace the old one:
$args['@entity'] = (is_object($entity_type->getLabel())) ? $entity_type->getLabel()->render() : $entity_type->getLabel();
Comment #9
audriusb CreditAttribution: audriusb commentedsubmitting a patch for latest 8.x-1.x dev
Comment #10
audriusb CreditAttribution: audriusb commentedComment #11
jmuzz CreditAttribution: jmuzz commentedDevelopment is moving to 8.x-3.x.
Comment #12
imclean CreditAttribution: imclean commentedComment #13
imclean CreditAttribution: imclean commented#12 is based on #9, it removes rogue changes.
I can confirm it works with ECK entities.
Comment #14
R UMESH CreditAttribution: R UMESH commentedI used the field collection fields in my eck entity type and was followed by this error .
Fortunately
@audriusb #9
patch works as required.
Thanks
Comment #15
Prashant.cSuddenly i also faced the same error and applied #12 resolves the issue.
Thanks for the patch.
Comment #16
ram4nd CreditAttribution: ram4nd as a volunteer commented