I'm trying to create a (no bundle) entity from a feed using entity API, but I keep running into strange issue. The code for the entities is this:

function my_entity_provision() {
  $a = entity_create('entityType', array(
    'pid' => NULL,
    'aid' => 1,


But when running it I run into these errors:

Warning: class_implements() [function.class-implements]: object or string expected in entity_create() (line 420 of ...../sites/all/modules/entity/entity.module).
Warning: in_array() expects parameter 2 to be array, boolean given in entity_create() (line 420 of ...../sites/all/modules/entity/entity.module).

I've tried looking on drupal and drupalcontrib for the correct implementation, but all code blocks show no text? :s

My code looks similar to Create Entity Programmatically in Drupal which does seem to work. (Since I have no bundle, I didn't define the type in the array, I read somewhere it can be omitted . But that made no difference anyway).

My entity info is as follows:

 * Implements hook_entity_info().
function my_entity_entity_info() {
  $return = array(
    'entityType' => array(
      'label' => t('entityType'),
      'controller class' => 'EntityAPIController',
      'base table' => 'entityTypes',
      'fieldable' => FALSE,
      'entity keys' => array(
        'id' => 'pid',
      'static cache' => TRUE,
      'view modes' => array(
        'full' => array(
          'label' => t('Full Entity'),
      'views controller class' => 'EntityDefaultViewsController',

  return $return;
  • "in_array() expects parameter 2 to be array, boolean given" - looks like something that you should create as an array, is not an array. Sorry but can't see what is it at first glance – Mołot Oct 30 '13 at 15:27
  • It is triggered by the my_entity_provision() function (it does not give an error if I don't call it). And the errors apply to entity_create. But I'm pretty sure the 2nd parameter is an array... – Neograph734 Oct 30 '13 at 15:31
  • 2nd parameter of entity_create is, but where is that in_array used? What is passed to in_array as it's second parameter? That's the point. – Mołot Oct 30 '13 at 15:35

Argh, it seems the two different entity modules (core & contrib) have confused me once again.

The EntityAPIController I chose as controller class has no method save(). It uses entity_save($entity_type, $entity); instead.

So the function had to be:

function my_entity_provision() {
  $a = entity_create('entityType', array(
    'pid' => NULL,
    'aid' => 1,

  entity_save('entityType', $a);
  • 1
    You might have been thinking of entities that have been extended using an EntityMetadataWrapper...they do have the save() method. I believe FieldCollection also implements the same method on the entity controller too (maybe some other contrib modules do too) – Clive Oct 30 '13 at 16:21

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.