What is the best way to add "last_imported" field into a view for a node entity-reference field joined to migrate_map table? I have a node which has an entity-reference field. The enitity in that field is being imported via Migration framework.
So if I call that entity fruit. MyNode has a field call fruit. Which is being migrated from an up-stream. Thus, it has a &quot;migrate_map&quot; table call &quot;migrate_map_fruit&quot;.
In which it has a column call &quot;sourceid&quot; which can be joined to &quot;fruit.id&quot; and then I want to extract a field call &quot;last_imported&quot; and display in the view.
What would be the best way to bring it to views ?
It's quite complex so feel free to reach me if you need more clarification.
So I found the solution to that.
You have to add relationship to referenced &quot;fruit&quot; entity to the view. And immediately following field will be available.
In my fruits_import.module.php I added hook_view_data() as follows.
/**
 * Implements hook_views_data().
 */
function fruits_import_views_data() {
  $views_data = [];
  // Exposing Migrate Map table.
  $views_data['migrate_map_fruit']['table'] = [
    'title' =&gt; t('Related migration'),
    'group' =&gt; t('Fruit Entity Migration Tables.'),
    // Watch out! This is not a base table, so we use a different key and
    // explain to Views how this table can be JOINed to our base table of
    // 'fruit'.
    'join'  =&gt; [
      // We are explaining Views how 'migrate_map_fruit' can be JOINed to 'fruit'.
      // By the way, you do not necessarily have to JOIN onto a base table. You
      // may as well JOIN in chain a few non-base tables. Although for a table
      // to become visible in Views UI, it must be connected one way or another
      // to a base table on which the view is being built.
      'fruit' =&gt; [
        // Column from 'fruit' table which will participate in the JOIN clause.
        'left_field' =&gt; 'id',
        // Column from 'migrate_map_fruit' table that will participate in the JOIN
        // clause.
        'field'      =&gt; 'destid1',
      ],
    ],
  ];
  // Exposing last imported col only for now. (We could expose other ones here)
  $views_data['migrate_map_fruit']['last_imported'] = [
    // Human friendly name for Views UI.
    'title' =&gt; t('Last Imported'),
    'help' =&gt; t('Timestamp for an fruit last imported.'),
    'field' =&gt; [
      // In the 'id' key we place the name of Views field plugin that is
      // responsible for operating the column. The id &quot;date&quot;
      // corresponds to \Drupal\views\Plugin\views\field\Date class. It is
      // an extremely simplistic straightforward field plugin that appends the
      // column into SELECT query (see ::query() method) and then displays the
      // fetched column as field output (see ::render() method).
      'id' =&gt; 'date',
    ],
  ];
  return $views_data;
}

Credits to awesome Views tutorial by Oleksandr