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',
),
),
),
));
}
Comment | File | Size | Author |
---|---|---|---|
#5 | eck-schema-exception-2470083-5.patch | 274 bytes | ben.kyriakou |
Comments
Comment #1
fmizzell CreditAttribution: fmizzell commentedThis 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().
Comment #2
fmizzell CreditAttribution: fmizzell commentedComment #3
lslinnet CreditAttribution: lslinnet as a volunteer commentedCurrently 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.
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.
Comment #4
ben.kyriakou CreditAttribution: ben.kyriakou as a volunteer commentedI 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:
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.
Comment #5
ben.kyriakou CreditAttribution: ben.kyriakou as a volunteer commentedI rolled this patch to solve the problem in my case.