Quote from modules/field/field.info.inc, lines 517 to 524:

/**
 * Returns all field definitions.
 *
 * @return
 *   An array of field definitions, keyed by field name. Each field has an
 *   additional property, 'bundles', which is an array of all the bundles to
 *   which this field belongs keyed by entity type.
 */

But, if $info gets no values the return value was NULL, instead of array() because the $fields variable is created insite the foreach.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bjaspan’s picture

Status: Active » Reviewed & tested by the community

Looks good. We could perhaps add a test for this but this is an extremely common code pattern in Drupal so I do not think it is necessary. But anyone wanting a bonus point could write one. Call field_info_fields(), delete all the fields it returns, and call it again, making sure it returns array() the second time.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, field.info_.inc-wrong_return_on_field_info_fields.patch, failed testing.

dmonroy’s picture

Steeps to reproduce the error i receive:

1. Install a clean Drupal 7 Alpha 6
2. Install Views (7.x-3.x-dev)
3. Go to views admin page

You will receive a warning on "..views/modules/field.views.inc" line 20, because we expect an array value, as explained on field_info_fields() documentation.

/**
 * Fragment of views/modules/field.views.inc
 **/

/*19*/    $data = array();
/*20*/    foreach (field_info_fields() as $field) { # <-- This is the line
/*21*/      if ($field['storage']['type'] != 'field_sql_storage') {

I think, this is not a views bug, because documentations say, the return value is an array.

Maybe it's something trivial, I did not like the warning shows

bjaspan’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
648 bytes

The patch did not apply because it was rolled from docroot/modules/field instead of docroot.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

andypost’s picture

Status: Fixed » Reviewed & tested by the community
FileSize
662 bytes

Should be $fields not $field!!! field_info_fields()

dmonroy’s picture

Thanks to everyone, I'm new with cvs and patches.

Please commit the patch sent by andypost, because the right variable name is fields.

PS
I'm sorry for my (very bad) english.

dmitrig01’s picture

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

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