I'm using Drupal 7.0
I have created a custom module that have 2 major responsabilities:
- Create a custom content type by code (that is not using the field api)
- Import content for that specified content type from a csv file.
This module used the function: drupal_form_submit($form_id, $form_state)
to import the content.
When I use my module to import content, I have the following errors:
Invalid offset supplied in field.attach.inc at line 198.
After doing a lot of investigation, I found some interesting stuff in the function:
function _field_invoke($op, $entity_type, $entity, &$a = NULL, &$b = NULL, $options = array())
The above function is calling _field_invoke_get_instances($entity_type, $bundle, $options)
(line 184)
This function return an array with all content type with all fields instance.
In my case, the Array returned for my content type is empty (no field instance in the array).
So, at line 189 of the _field_invoke function ($field_name = $instance['field_name']
) :
The instruction is not valid because the offset 'field_name' doesn't exist.
I suggest that the function _field_invoke should be modified as follow:
Insert an if statement between line 188 and line 189 to verify the validity of the 'field_name' offset.
line 188 foreach ($instances as $instance) {
if (isset($instance['field_name'])) {
line 189 $field_name = $instance['field_name'];
Thanks in advance !