You are here

function ServiceAuditFilesUsedNotManaged::_auditfiles_used_not_managed_get_file_data in Audit Files 8

Retrieves information about an individual file from the database.

File

src/ServiceAuditFilesUsedNotManaged.php, line 35
providing the service that used in 'used not managed' functionality.

Class

ServiceAuditFilesUsedNotManaged

Namespace

Drupal\auditfiles

Code

function _auditfiles_used_not_managed_get_file_data($file_id) {

  // Get the file information for the specified file ID from the database.
  $connection = Database::getConnection();
  $query = 'SELECT * FROM {file_usage} WHERE fid = ' . $file_id;
  $file = $connection
    ->query($query)
    ->fetchObject();
  $url = Url::fromUri('internal:/' . $file->type . '/' . $file->id);
  $result = Link::fromTextAndUrl($file->type . '/' . $file->id, $url)
    ->toString();
  return [
    'fid' => $file->fid,
    'module' => $file->module . ' ' . t('module'),
    'id' => $result,
    'count' => $file->count,
  ];
}