How to get parent node from a attachment in drupal8 search api results I have apachesolr index search with Search API attachments. In the results I get a link to the file but I would like to get a link to the parent node. I tried in the view but there is no such field with relationship to file usage.
I wrote the following in a module to override the field fid in the view but it returns an error

function hook_preprocess_views_view_field(&amp;$variables) {
$view = $variables['view'];
$field = $variables['field'];
    if ($view-&gt;storage-&gt;id() == 'saa' &amp;&amp;
    $view-&gt;current_display == 'page_1' &amp;&amp;
    $field-&gt;field == 'fid') {
        $fid =  $variables['output']; 
        $file = \Drupal\file\Entity\File::load($fid);
        $file_usage = \Drupal::service('file.usage')-&gt;listUsage($file);
        $variables['results'] = $file_usage;
    }
}


It returns


  The website encountered an unexpected error. Please try again later.
  TypeError: Argument 1 passed to Drupal\file\FileUsage\DatabaseFileUsageBackend::listUsage() must implement interface Drupal\file\FileInterface, null given, called in /home/rebecca/public_html/new5/modules/pdf_app/pdf_app.module on line 262 in Drupal\file\FileUsage\DatabaseFileUsageBackend->listUsage() (line 123 of core/modules/file/src/FileUsage/DatabaseFileUsageBackend.php).
$file should be instance of Drupal\file\FileInterface but in this case $file is null so you should check first on $file something 

function hook_preprocess_views_view_field(&amp;$variables) {
  $view = $variables['view'];
  $field = $variables['field'];
  if ($view-&gt;storage-&gt;id() == 'saa' &amp;&amp;
    $view-&gt;current_display == 'page_1' &amp;&amp;
    $field-&gt;field == 'fid') {
    $fid = $variables['output']-&gt;__toString();
    $file = \Drupal\file\Entity\File::load($fid);
    if ($file &amp;&amp; $file instanceof Drupal\file\FileInterface) {
      $file_usage = \Drupal::service('file.usage')-&gt;listUsage($file);
      $variables['output'] = $file_usage;
    }
  }
}