I created an entity type using Entity API and made it exportable. The export link works properly but on Import I have this error:

Fatal error: Call to a member function label() on a non-object in [...]\sites\all\modules\entity\entity.module on line 903

I couldn't find any reason.
Here's my hook_entity_info():

$return = array(
  'event' => array(
    'label' => t('Event'),
    'entity class' => 'EventClass',
    'controller class' => 'EventController',
    'base table' => 'calendar_events',
    'fieldable' => TRUE,
    'entity keys' => array(
      'id' => 'eid',
    'load hook' => 'events_load',
    'view modes' => array(
      'full' => array(
        'label' => t('Default'),
        'custom settings' => FALSE,
    'label callback' => 'entity_class_label',
    'uri callback' => 'entity_class_uri',
    'module' => 'events',
    'access callback' => 'event_access',
    'exportable' => TRUE,
    'admin ui' => array(
      'path' => 'admin/structure/events',
      'file' => 'events.admin.inc',
      'controller class' => 'EventsUIController',

Tell me if you need more information.

I figured that the error has been occurred in entity_class_label($entity) in sites/all/modules/entity/entity.module:903. I printed the content of $entity and it seems it is NULL!
Why is it NULL?

  • 1
    To add to Clive's solution, you may have better luck posting in the Entity API issue queue instead for support on this. Issues with modules and themes <a href="drupal.stackexchange.com/faq#questions">are considered out of scope for this site</a>. – David Watson Feb 29 '12 at 5:25
  • You would get far with a debug_backtrace call – googletorp Feb 29 '12 at 9:02
  • I was having this same problem, and debug_backtrace helped find the problem. In my case, I changed the menu paths for my entity from contact/%id to news/contact/%id, but forgot to change the page arguments position from 1 to 2. – Johnathan Elmore Dec 6 '12 at 19:28

It looks like this is a bug in the Entity API module.

An issue with exactly the same error message was reported here to do with the Profile2 module (which uses Entity API pretty heavily).

The upshot of that post is that the problem is an Entity API bug, details of which you can see at: Load reference field when building contents.

As you can see from the above there are patches available to fix the problem. The most recent patch that passed testing was on the 16th November 2011.

When you look at the Entity API module's latest stable release you can see it's date sas the 10th November 2011. This means that the patch probably hasn't made it into the stable version yet, so won't have been fixed in your version of the module.

There are two things you can do:

  • Upgrade to the dev version of the Entity API module (of course the usual amount of caution should be taken and you probably won't want to do this for a live site).
  • Apply the patch to the entity.controller.inc file that seems to have solved the problem for other users.
  • Thanks for reply. I tried both ways but neither worked! – Pedram Behroozi Feb 26 '12 at 6:20
  • Neither worked for me as well. – Bart Jul 3 '12 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.