Problem/Motivation

The various wrappers for _field_info_collate_fields() do not return the same structure for field data. For example, while field_info_field() returns the field type, field_info_instances() does not. This results in unnecessarily redundant code. For example, to check the field types in a bundle, one would need to do something like the following:

  $fields = array();
  $possible = field_info_instances($entity_type, $bundle);

  foreach ($possible as $field_name => $info) {
    $new_info = field_info_field($field_name);
    if ($new_info['type'] == 'mytype') {
      $fields[$field_name] = $new_info;
    }
  }

Proposed resolution

Standardize the field properties across the cached "bins" of $info in _field_info_collate_fields().

Memory usage is a consideration; see #1040790: _field_info_collate_fields() memory usage. However, since the properties are already stored in other "bins," adding them where they are missing need not necessarily add much overhead.

Remaining tasks

TBD

User interface changes

None.

API changes

Each field would have the same set of attributes when returned by any of the seven wrapper functions for _field_info_collate_fields().

Comments

yched’s picture

Status: Active » Closed (works as designed)

That's inherent to the separation between fields and instances. field_info_fields() lists fields, field_info_instances() lists instances, those are different things, and you can't expect to find properties of one in the other.

As such, this is "by design". A $field has a type, an $instance is an instance of a $field, which has a type. We won't be duplicating the $field structure (or parts of it) within the $instance.

If / when the much-expected "plugins" mechanism from the Web services initiative lands in core, an object-oriented reformulation of the Field API could probably alleviate that, by letting an $instance object hold a *reference* to its $field object. I.e you can do something like $instance->field->type.

xjm’s picture

Re: $instance->field->type -- This would be awesome, that sort of thing across the Field API. Sounds like it's a ways off, though?