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'.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lodey created an issue. See original summary.

jmuzz’s picture

Status: Active » Postponed (maintainer needs more info)

I 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.

lodey’s picture

Hi 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?

lodey’s picture

Nope - 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.

jmuzz’s picture

Status: Postponed (maintainer needs more info) » Needs review

Thanks @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.

jmuzz’s picture

Title: Fatal error: Call to a member function render() on a non-object » Fatal error when using field collections in ECK entities
Status: Needs review » Needs work
Danny Englander’s picture

I 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.

audriusb’s picture

#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();

audriusb’s picture

submitting a patch for latest 8.x-1.x dev

audriusb’s picture

Status: Needs work » Needs review
jmuzz’s picture

Version: 8.x-1.x-dev » 8.x-3.x-dev

Development is moving to 8.x-3.x.

imclean’s picture

imclean’s picture

#12 is based on #9, it removes rogue changes.

I can confirm it works with ECK entities.

R UMESH’s picture

Status: Needs review » Reviewed & tested by the community

I used the field collection fields in my eck entity type and was followed by this error .
Fortunately

@audriusb #9

patch works as required.

Thanks

Prashant.c’s picture

Suddenly i also faced the same error and applied #12 resolves the issue.

Thanks for the patch.

ram4nd’s picture

Status: Reviewed & tested by the community » Closed (won't fix)