Problem/Motivation

(From #1371938: hook_field_delete() no longer invoked during field_purge_data().)

  • The documentation for field_info_field() states:

    $field_name can only refer to a non-deleted, active field. Use field_read_fields() to retrieve information on deleted or inactive fields.

  • The documentation for field_info_field_by_id() indicates it also may be used for deleted fields:

    $field_id The id of the field to retrieve. $field_id can refer to a deleted field.

  • In most cases it is probably easier and more desirable to use field_info_field_by_id() than field_read_fields() for a single field.

Proposed resolution

  • Change the documentation for field_info_field() to read:

    $field_name The name of the field to retrieve. $field_name can only refer to a non-deleted, active field. Use field_info_field_by_id() or field_read_fields() to retrieve information on deleted or inactive fields.

Remaining tasks

  • Create a documentation patch for the above change.

User interface changes

  • None.

API changes

  • None.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xjm’s picture

Assigned: Unassigned » xjm
Issue tags: +Novice, +Needs backport to D7

Tagging as novice, but assigning to myself for the moment.

sven.lauer’s picture

The proposed resolution is not quite adequate: field_info_field_by_id() does not work for inactive fields. It passes on the ['fields'][$field_id] subarray from _field_info_collate_fields(), which:

fields: Array of existing fields, keyed by field ID. This element lists deleted and non-deleted fields, but not inactive ones. Each field has an additional element, 'bundles', which is an array of all non-deleted instances of that field.

So for inactive fields, one has to use field_read_fields() (which has an 'include_active' option and queries the field_config table directly).

Accordingly, the return value doc at
http://api.drupal.org/api/drupal/modules--field--field.info.inc/function...
is false/misleading, too:

The field array, as returned by field_read_fields(), with an additional element 'bundles', whose value is an array of all the bundles this field belongs to.

There should be a mention that the function returns nothing for inactive fields.

xjm’s picture

Assigned: xjm » Unassigned

Looks like the person who wanted to work on this is not going to, so it's free for the taking.

sven.lauer’s picture

Here is a patch, taking into account what I pointed out in #2.

sven.lauer’s picture

Status: Active » Needs review
sven.lauer’s picture

Uhm, no. The previous patch contains a completely garbled sentence.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

I agree with the assessment in #2, and the patch in #6 is good. Thanks for such careful attention to the documentation!

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x and 7.x. Thanks!

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