Problem

After installing Node Gallery to a basic Drupal 7.16 (unchanged after updating to 7.17) install, undefined index notices of the following kind begin to get displayed whenever handling fields (adding, changing settings, etc.)

Notice: Undefined index: module in _field_info_prepare_instance_widget() (line 387 of W:\sli\drupal\modules\field\field.info.inc).
Notice: Undefined index: module in _field_info_prepare_instance_display() (line 355 of W:\sli\drupal\modules\field\field.info.inc).

I was able to ascertain that it was indeed Node Gallery causing this by disabling and re-enabling it (notices disappeared and reappeared).

As far as I have understood the issue, the underlying cause lies in

  • two variables, $widget_type and $formatter_type not being explicitly set by Node Gallery,
  • coupled with the fact that the Field module's fields.info.inc omits the else part of an if / else statement that (very probably?) is actually meant to handle (empty) cases when the default should be used. (see ongoing issue Undefined index _field_info_prepare_instance_widget @ core)

Proposed resolution

While IMHO the issue should be resolved where it is generated, namely in Fields itself, it has been suggested that we also bring this to the attention of developers working on modules that trigger these notices by leaving the besaid variables undefined.
The immediate resolution of this problem with respect to Node Gallery thus would be to set these variables on module level.

Being a novice to Drupal, I may be missing something in all this and leave it to greater minds here to decide whether this additional clarifying on contrib level is a good thing (based on coding best practice principles alone, I would tend towards yes, which is also why I am posting this issue here).
Thanks!

Comments

zengenuity’s picture

I think it's a little more complex than just missing indexes. As far as I can tell, there aren't any missing in NG, but there was a mention in one of those threads about calls to entity_get_info() inside hook_field_info() being a problem. Attached is a patch that works around any calls to entity_get_info(). It seems to eliminate the notices for me. Please let me know if it works for you.

calliandra’s picture

Yes your workaround does also work for me.

I tried to find out how these parts go together, especially how the entity_get_info(), and avoiding it, ultimately relates to the lines of code in Fields which end up generating, or not, those notices.
Unfortunately, however, this is as yet way beyond my understanding... :)

zengenuity’s picture

Status: Active » Fixed

Committed to dev

vchu2012’s picture

Dear Sir,

I'm new to this module. And how to apply the patch?

vchu

fugazi’s picture

@ vchu2012 in the new dev version of the patch is anchored. Otherwise, easier for me away the patch on the file, open the node_gallery_api.module file with the line minus remove and replace with plus. Click here for more info

vchu2012’s picture

I got this error when I try to apply the patch
and
I'm using the version that you mentioned in previous post.

--- b/node_gallery_api.module
+++ a/node_gallery_api.module
@@ -677,16 +677,9 @@
* Implements hook_field_info().
*/
function node_gallery_api_field_info($field_name = NULL) {
- // We can't use node_gallery_api_get_relationship_type() here because it
- // creates PHP notices from this core issue: http://drupal.org/node/1001060.
- $relationship_types = db_select('node_gallery_relationship_type', 'ngrt')
- ->fields('ngrt')
- ->execute();
+ $relationship_types = node_gallery_api_get_relationship_type(NULL, NULL, NULL, TRUE);
if (!empty($relationship_types)) {
- foreach ($relationship_types as $relationship_type) {
- $relationship_type->settings = unserialize($relationship_type->settings);
- $relationship_type->item_types = $relationship_type->settings['relationship_type']['item_types'];
- $relationship_type->gallery_types = $relationship_type->settings['relationship_type']['gallery_types'];
+ foreach($relationship_types as $relationship_type) {

$name = node_gallery_api_get_item_field_name(NULL, NULL, $relationship_type->id);
$items[$name] = array(

zengenuity’s picture

@vchu2012, if you aren't able to apply the patch, your best option is to wait a few days. I'm going to release beta2 this weekend, after I fix a few more issues. beta2 will include the changes in this patch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.