API page: https://api.drupal.org/api/drupal/core%21modules%21field%21field.api.php...

As seen in this comment as well https://api.drupal.org/comment/57233#comment-57233 (yes, I commented first, sorry) the code sample is wrong in the documentation.
The 'field types' key is actually 'field_types' so the correct code would be:

function hook_field_formatter_info_alter(array &$info) {
  // Let a new field type re-use an existing formatter.
  $info['text_default']['field_types'][] = 'my_field_type';
}
CommentFileSizeAuthor
#1 incorrect_doc-2354005-1.patch542 bytesbenelori

Comments

benelori’s picture

StatusFileSize
new542 bytes

Submitted patch for this

benelori’s picture

Status: Active » Needs review
jhodgdon’s picture

Status: Needs review » Fixed

Thanks! Yes, it was "field types" with a space in Drupal 7, but I agree it's been changed in Drupal 8, as you can see in telephone_field_formatter_info_alter() in Drupal 8. In Drupal 8 the hook alters collected annotation information, and in annotation the info is "field_types" without the space.

Committed to 8.0.x.

  • jhodgdon committed 1a420c9 on
    Issue #2354005 by benelori: Fix sample function body for...

Status: Fixed » Closed (fixed)

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