Limit entity reference field formatter to certain entity types I've created an entity reference field formatter. It works fine. However, the field formatter will only work properly on entities of type user, so if the referenced entity type is different, I don't want the formatter to appear in the list of options.

I tried adding entity_types = { user } to my annotation for the formatter, but this didn't work. I'm suspecting it cannot even be done, but I thought I'd ask here before opening up an issue in core, to suggest it for future development. 

Does anyone know if this can be done, and if it can, how?
I think this will work...

There is an isApplicable() method in Drupal\Core\Field\FormatterBase. You can implement it in your FieldFormatter class like this:

public static function isApplicable(FieldDefinitionInterface $field_definition) {
  return ($field_definition-&gt;getFieldStorageDefinition()-&gt;getSetting('target_type') == 'user');
}