You are here

public function ServiceAuditFilesUsedNotManaged::auditfilesUsedNotManagedGetFileData in Audit Files 8.2

Same name and namespace in other branches
  1. 8.3 src/ServiceAuditFilesUsedNotManaged.php \Drupal\auditfiles\ServiceAuditFilesUsedNotManaged::auditfilesUsedNotManagedGetFileData()
  2. 4.x src/ServiceAuditFilesUsedNotManaged.php \Drupal\auditfiles\ServiceAuditFilesUsedNotManaged::auditfilesUsedNotManagedGetFileData()

Retrieves information about an individual file from the database.

File

src/ServiceAuditFilesUsedNotManaged.php, line 79

Class

ServiceAuditFilesUsedNotManaged
Form for Files used not managed functionality.

Namespace

Drupal\auditfiles

Code

public function auditfilesUsedNotManagedGetFileData($file_id) {

  // Get the file information for the specified file ID from the database.
  $connection = $this->connection;
  $query = 'SELECT * FROM {file_usage} WHERE fid = :file_id';
  $file = $connection
    ->query($query, [
    'file_id' => $file_id,
  ])
    ->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 . ' ' . $this
      ->t('module'),
    'id' => $result,
    'count' => $file->count,
  ];
}