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()
thanfield_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.
Comment | File | Size | Author |
---|---|---|---|
#6 | doc-field_info_field_by_id-works-for-deleted-fields-1372280-1.patch | 1012 bytes | sven.lauer |
#4 | doc-field_info_field_by_id-works-for-deleted-fields-1372280.patch | 1.01 KB | sven.lauer |
Comments
Comment #1
xjmTagging as novice, but assigning to myself for the moment.
Comment #2
sven.lauer CreditAttribution: sven.lauer commentedThe 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:
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:
There should be a mention that the function returns nothing for inactive fields.
Comment #3
xjmLooks like the person who wanted to work on this is not going to, so it's free for the taking.
Comment #4
sven.lauer CreditAttribution: sven.lauer commentedHere is a patch, taking into account what I pointed out in #2.
Comment #5
sven.lauer CreditAttribution: sven.lauer commentedComment #6
sven.lauer CreditAttribution: sven.lauer commentedUhm, no. The previous patch contains a completely garbled sentence.
Comment #7
jhodgdonI agree with the assessment in #2, and the patch in #6 is good. Thanks for such careful attention to the documentation!
Comment #8
webchickCommitted and pushed to 8.x and 7.x. Thanks!