You are here

function views_handler_field_file_link_usage::render_link in File Entity (fieldable files) 7.2

Same name and namespace in other branches
  1. 7.3 views/views_handler_field_file_link_usage.inc \views_handler_field_file_link_usage::render_link()

Renders the link.

Overrides views_handler_field_file_link::render_link

File

views/views_handler_field_file_link_usage.inc, line 40
Definition of views_handler_field_file_link_usage.

Class

views_handler_field_file_link_usage
Field handler to present a link to view the usage of a file.

Code

function render_link($file, $values) {

  // Ensure user has access to update this file.
  if (!file_entity_access('update', $file)) {
    return;
  }
  $this->options['alter']['make_link'] = TRUE;
  $this->options['alter']['path'] = "file/{$file->fid}/usage";
  $this->options['alter']['query'] = drupal_get_destination();

  // Get total count for each file.
  $total_count = 0;
  $file_usage = file_usage_list($file);
  $count_entities_once = !empty($this->options['count_entities_once']);
  foreach ($file_usage as $module => $usage) {
    foreach ($usage as $entity_type => $entity_ids) {
      if ($count_entities_once) {

        // Just count each unique entity once.
        $total_count += count($entity_ids);
      }
      else {

        // Count multiple usages for each entity.
        foreach ($entity_ids as $id => $count) {
          $total_count += $count;
        }
      }
    }
  }
  $text = !empty($this->options['text']) ? $this->options['text'] : format_plural((int) $total_count, '1 place', '@count places');
  return $text;
}