How does the UserData plugin get the correct value? The User module defines a UserData plugin for the Views module, which allows to access the user.data service from a view. Its render() method contains the following code.

$uid = $this-&gt;getValue($values);
$data = $this-&gt;userData-&gt;get($this-&gt;options['data_module'], $uid, $this-&gt;options['data_name']);

// Don't sanitize if no value was found.
if (isset($data)) {
  return $this-&gt;sanitizeValue($data);
}


}

How does the Views module know the plugin require a user ID? In other words, how does the Views module know that is a field plugin associated with the User entity and not another entity?

The annotation for the plugin is simply the following one.

@ViewsField("user_data")


Neither its create() nor its constructor method set something that would make clear to which entity the plugin is associated.

public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
  return new static($configuration, $plugin_id, $plugin_definition, $container-&gt;get('user.data'), $container-&gt;get('module_handler'));
}




public function __construct(array $configuration, $plugin_id, $plugin_definition, UserDataInterface $user_data, ModuleHandlerInterface $module_handler) {
  parent::__construct($configuration, $plugin_id, $plugin_definition);

  $this-&gt;userData = $user_data;
  $this-&gt;moduleHandler = $module_handler;
}
The available fields for the user entity are defined in Drupal\user\UserViewsData::getViewsData():

$data['users']['data'] = [
  'title' =&gt; $this-&gt;t('Data'),
  'help' =&gt; $this-&gt;t('Provides access to the user data service.'),
  'real field' =&gt; 'uid',
  'field' =&gt; [
    'id' =&gt; 'user_data',
  ],
];


This attaches the field user_data to the user entity.