1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Definition of views_handler_field_file_link_usage.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Field handler to present a link to view the usage of a file.
|
10 |
|
|
*
|
11 |
|
|
* @ingroup views_field_handlers
|
12 |
|
|
*/
|
13 |
|
|
class views_handler_field_file_link_usage extends views_handler_field_file_link {
|
14 |
|
|
|
15 |
|
|
/**
|
16 |
|
|
* Renders the link.
|
17 |
|
|
*/
|
18 |
|
|
function render_link($file, $values) {
|
19 |
|
|
// Ensure user has access to update this file.
|
20 |
|
|
if (!file_entity_access('update', $file)) {
|
21 |
|
|
return;
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
$this->options['alter']['make_link'] = TRUE;
|
25 |
|
|
$this->options['alter']['path'] = "file/$file->fid/usage";
|
26 |
|
|
$this->options['alter']['query'] = drupal_get_destination();
|
27 |
|
|
|
28 |
ca0757b9
|
Assos Assos
|
// Get total count for each file.
|
29 |
|
|
$total_count = 0;
|
30 |
|
|
foreach (file_usage_list($file) as $module => $usage) {
|
31 |
|
|
foreach ($usage as $entity_type => $entity_ids) {
|
32 |
|
|
foreach ($entity_ids as $id => $count) {
|
33 |
|
|
$total_count += $count;
|
34 |
|
|
}
|
35 |
|
|
}
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
$text = !empty($this->options['text']) ? $this->options['text'] : format_plural((int) $total_count, '1 place', '@count places');
|
39 |
85ad3d82
|
Assos Assos
|
return $text;
|
40 |
|
|
}
|
41 |
|
|
} |