In "field.crud.inc" the documentation for field_create_instance() has a mistake.

It says that "weight" is a property of "instance", when in reality, it must be a property of "widget".
It is used by _field_write_instance() to set the weight of the widget for the given bundle.

References:
field_create_instance()
_field_write_instance()

Cheers

CommentFileSizeAuthor
#5 drupal.1107376-5.patch516 bytesjhedstrom

Comments

jhodgdon’s picture

Status: Active » Postponed (maintainer needs more info)

Hm. Really? I think that the instance has a weight also for purposes of displaying the fields on (for instance) the node/# page, which has nothing to do with widgets?

jm.federico’s picture

It is the widget's weight the one that controls where the info ins displayed.
I've checked the code and everywhere it is used, it uses the widget's weight.

jhodgdon’s picture

Title: Weight is a property of "widget" not of "instance" » Weight not a property of a field instance, so doc shouldn't say it is

Hm. It looks to me as though _field_write_instance (see link above in original issue report) is using both the widget's weight and the display mode formatter's weight:

if (!isset($instance['widget']['weight'])) {
    $max_weight = field_info_max_weight($instance['entity_type'], $instance['bundle'], 'form');
    $instance['widget']['weight'] = isset($max_weight) ? $max_weight + 1 : 0;
  }
...
   if (!isset($display['weight'])) {
      $max_weight = field_info_max_weight($instance['entity_type'], $instance['bundle'], $view_mode);
      $display['weight'] = isset($max_weight) ? $max_weight + 1 : 0;
    }

So it does look like weight is not a property of the instance itself, and the doc should just have the weight item removed from it.

jhodgdon’s picture

Version: 7.x-dev » 8.x-dev
Status: Postponed (maintainer needs more info) » Active

Should be fixed in 8.x first then 7.x

jhedstrom’s picture

Status: Active » Needs review
StatusFileSize
new516 bytes

Here's a patch against 8.x that simply removes the weight property from the doc for field_create_instance().

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Thanks jhedstrom! Patch looks good for d8 and d7.

yched’s picture

Yup, remnant of the time when fields where not reorderable view mode by view mode, i.e. weight was for the instance as a whole. That one occurrence got overlooked.

Confirming rtbc.

dries’s picture

Status: Reviewed & tested by the community » Fixed

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

Status: Fixed » Closed (fixed)

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