diff --git a/file_entity.module b/file_entity.module index 3b36595..e585fe6 100644 --- a/file_entity.module +++ b/file_entity.module @@ -150,6 +150,16 @@ function file_entity_menu() { 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); + $items['file/%file/usage'] = array( + 'title' => 'Usage', + 'page callback' => 'file_entity_usage_page', + 'page arguments' => array(1), + 'access callback' => 'file_entity_access', + 'access arguments' => array('view'), + 'type' => MENU_LOCAL_TASK, + 'context' => MENU_CONTEXT_PAGE, + 'file' => 'file_entity.pages.inc', + ); $items['file/%file/edit'] = array( 'title' => 'Edit', 'page callback' => 'drupal_get_form', @@ -335,7 +345,7 @@ function file_entity_theme() { 'file_entity_file_link' => array( 'variables' => array('file' => NULL, 'icon_directory' => NULL), 'file' => 'file_entity.theme.inc', - ) + ), ); } diff --git a/file_entity.pages.inc b/file_entity.pages.inc index ee58c90..77a28ce 100644 --- a/file_entity.pages.inc +++ b/file_entity.pages.inc @@ -57,6 +57,51 @@ function file_entity_add_upload($form, &$form_state, array $options = array()) { return $form; } +function file_entity_usage_page($file) { + + foreach (file_usage_list($file) as $module => $usage) { + $info = system_get_info('module', $module); + $item = array( + 'data' => $info['name'], + 'children' => array(), + ); + foreach ($usage as $entity_type => $entity_ids) { + $entity_info = entity_get_info($entity_type); + $entities = entity_load($entity_type, array_keys($entity_ids)); + foreach ($entity_ids as $entity_id => $count) { + $label = entity_label($entity_type, $entities[$entity_id]); + $rows[] = array( + $entity_type, + l($label, $entity_type . '/' . $entity_id), + $count, + ); + } + } + } + if (empty($rows)) { + $rows = array(); + } + $header[] = array( + 'data' => t('Type'), + ); + $header[] = array( + 'data' => t('Title'), + ); + $header[] = array( + 'data' => t('Count'), + ); + + $build['usage_table'] = array( + '#theme' => 'table', + '#header' => $header, + '#rows' => $rows, + '#prefix' => t('This table lists all of the places where @filename is used.', + array('@filename' => $file->filename)), + '#empty' => 'This file is not currently used', + ); + return $build; +} + /** * Upload a file. */