I try to build an entity in my custom modules hook_install().

While installation of my module I get following warning displayed:

array_keys() expects parameter 1 to be array, null given common.inc:7154

I tracked it down in the debugger for some time:
The call to drupal_get_schema() seems to not give back the schema information of the newly created entity-base-table "eck_[entity-type]".

To fix this I now do a call like following to refresh the schema cache before adding fields to the bundle with Bundle->addField():

drupal_get_schema('eck_my_type', TRUE);

This call seems unnatural to me. Should be done by eck internally.

Here's my example hook_install():



function fancy_module_install() {


  $my_type = new EntityType();
  $my_type->name = 'my_type';
  $my_type->label = 'Fancy Entity';
  $my_type->addProperty('uid', 'Author', 'integer', 'author');
  $my_type->addProperty('created', 'Created', 'integer', 'created');
  $my_type->addProperty('changed', 'Changed', 'integer', 'changed');

  $my_type->save();


  $simple_bundle = new Bundle();
  $simple_bundle->entity_type = 'my_type';
  $simple_bundle->name = 'simple';
  $simple_bundle->label = 'Simple (even though fancy)';

  $simple_bundle->save();


  drupal_get_schema('eck_my_type', TRUE);

  $simple_bundle->addField('text', array(
    'field' => array(
      'field_name' => 'title_field',
    ),
    'instance' => array(
      'display' => array(
        'default' => array(
          'label' => 'hidden',
        ),
      ),
    ),
  ));

}

CommentFileSizeAuthor
#5 eck-schema-exception-2470083-5.patch274 bytesben.kyriakou
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fmizzell’s picture

This is true, it is a bug that we are not able to use the ECK API without having to clean afterwards, but this was a decision that was made to make the module perform better. Previously we used to clear caches on ->save() which worked great, but it also meant that generally we were clearing the same caches multiple times during the same request. The solution was to remove the cache clearing from ->save() and creating a simple function that one can call to clean all the relevant caches at the end of a set of ECK operation like you are doing in your example: eck_clean_up().

I think this is more a matter of documentation at this point, unless you have a better solution than what we have now. For more information on the issue follow the code in eck_init().

fmizzell’s picture

Version: 7.x-2.0-rc7 » 7.x-2.x-dev
Component: Code » Documentation
Category: Bug report » Task
lslinnet’s picture

Currently the cache clearing doesn't properly works, basically breaks when running a Site Install.

Setup is creating the entity in an install hook, and having fields for the entity in features.

Invalid argument supplied for foreach() common.inc:7176                                                                                                                                                 [warning]
array_keys() expects parameter 1 to be array, null given common.inc:7196                                                                                                                        [warning]
Invalid argument supplied for foreach() common.inc:7176                                                                                                                                                 [warning]
array_keys() expects parameter 1 to be array, null given common.inc:7196                                                                                                                        [warning]

Tracked them down to the schema not being there for when features was trying to add fields to the newly created entity.

I solved this issue by calling eck_clean_up() just after creating the entity.

I do not think you can write this off as a Documentation issue, seems like there is a hard case of cache handling for the module that needs another look.

ben.kyriakou’s picture

Component: Documentation » Code
Category: Task » Bug report

I agree that this is a bug and not a documentation issue - I've run across this when trying to write a Simpletest that involves a featured eck entity. Enabling the feature causes it to throw the exceptions:

Exception Warning    common.inc        7204 drupal_schema_field_types()        
    Invalid argument supplied for foreach()
Exception Warning    common.inc        7224 drupal_schema_fields_sql()         
    array_keys() expects parameter 1 to be array, null given

since the schema for the table isn't correctly reflected after the entity is created. There must be a way to intelligently create the entity and clear the cache without clearing the cache for every operation.

ben.kyriakou’s picture

I rolled this patch to solve the problem in my case.