You are here

function theme_apachesolr_search_snippets__file in Apache Solr Attachments 7

Same name and namespace in other branches
  1. 6.3 apachesolr_attachments.module \theme_apachesolr_search_snippets__file()

@todo Vastly improve this theming function

Parameters

type $vars:

Return value

type

File

./apachesolr_attachments.module, line 710
Provides a file attachment search implementation for use with the Apache Solr module

Code

function theme_apachesolr_search_snippets__file($vars) {
  $doc = $vars['doc'];
  $snippets = $vars['flattened_snippets'];
  $parent_entity_links = array();

  // Retrieve our parent entities. They have been saved as
  // a small serialized entity
  foreach ($doc->zm_parent_entity as $parent_entity_encoded) {
    $parent_decoded = (object) drupal_json_decode($parent_entity_encoded);

    // Extract entity id from parent. List fetches the first item from the array.
    list($id) = entity_extract_ids($parent_decoded->entity_type, $parent_decoded);

    // Load parent entity
    $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']);
  }
  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,
        ),
      )),
    ));
  }
  else {
    $file_type = t('@filemime', array(
      '@filemime' => $doc->ss_filemime,
    ));
  }
  return implode(' ... ', $snippets) . '<span>' . $file_type . ' <em>attached to:</em>' . implode(', ', $parent_entity_links) . '</span>';
}