As of Drupal 8.4.2 this still an issue.
Here is how I fixed it having a custom Entity Content "itrack_notification" and an entity reference field "entity_reference" created with BaseFieldDefinition
to be able to use this field as a contextual filter.
In my_module/src/Entity/myEntityViewsData.php
/**
* {@inheritdoc}
*/
public function getViewsData() {
$data = parent::getViewsData();
$reference_field_name = 'receivers';
$entity_type = 'itrack_notification';
$handler_values = [
'field' => "{$reference_field_name}_target_id",
'table' => "{$entity_type}__{$reference_field_name}",
'field_name' => $reference_field_name,
'entity_type' => $entity_type,
'additional fields' => [
"field_{$reference_field_name}_target_id",
],
];
$data["{$entity_type}__{$reference_field_name}"][$reference_field_name]['relationship']['relationship field'] = "{$reference_field_name}_target_id";
$data["{$entity_type}__{$reference_field_name}"]["{$reference_field_name}_target_id"] = [
'group' => $this->t('ITrack Notification'),
'argument' => [
'title' => $this->t('Receivers - has User ID'),
'help' => $this->t('Holds the receiver User ID.'),
'id' => 'numeric',
] + $handler_values,
];
// Unset unusable view data handlers.
unset($data["{$entity_type}__{$reference_field_name}"][$reference_field_name]['argument']);
return $data;
}
If you need the fix for using the field as a filter
or sort
have a look at this patch.