diff --git a/apachesolr_attachments.module b/apachesolr_attachments.module
index 8876adb..586fd5d 100644
--- a/apachesolr_attachments.module
+++ b/apachesolr_attachments.module
@@ -724,11 +724,15 @@ function theme_apachesolr_search_snippets__file($vars) {
$load = entity_load($parent_decoded->entity_type, array($id));
$parent_entity = array_shift($load);
- $parent_entity_uri = entity_uri($parent_decoded->entity_type, $parent_entity);
- $parent_entity_uri['options']['absolute'] = TRUE;
- $parent_label = entity_label($parent_decoded->entity_type, $parent_entity);
- $parent_entity_links[] = l($parent_label, $parent_entity_uri['path'], $parent_entity_uri['options']);
+ //Handle case where entity no longer exists but file is still in the index
+ if (!empty($parent_entity)) {
+ $parent_entity_uri = entity_uri($parent_decoded->entity_type, $parent_entity);
+ $parent_entity_uri['options']['absolute'] = TRUE;
+ $parent_label = entity_label($parent_decoded->entity_type, $parent_entity);
+ $parent_entity_links[] = l($parent_label, $parent_entity_uri['path'], $parent_entity_uri['options']);
+ }
}
+ $snippet_suffix = (!empty($parent_entity_links)) ? ' attached to:' . implode(', ', $parent_entity_links) . '':'';
if (module_exists('file')) {
$file_type = t('!icon @filemime', array('@filemime' => $doc->ss_filemime, '!icon' => theme('file_icon', array('file' => (object) array('filemime' => $doc->ss_filemime)))));
@@ -737,7 +741,7 @@ function theme_apachesolr_search_snippets__file($vars) {
$file_type = t('@filemime', array('@filemime' => $doc->ss_filemime));
}
- return implode(' ... ', $snippets) . '' . $file_type . ' attached to:' . implode(', ', $parent_entity_links) . '';
+ return implode(' ... ', $snippets) . '' . $file_type . $snippet_suffix;
}
/**