You are here

public function ServiceAuditFilesReferencedNotUsed::auditfilesReferencedNotUsedGetFileData in Audit Files 8.2

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

Retrieves information about an individual file from the database.

Parameters

array $row_data: The data to use for creating the row.

Return value

array The row for the table on the report, with the file's information formatted for display.

File

src/ServiceAuditFilesReferencedNotUsed.php, line 145

Class

ServiceAuditFilesReferencedNotUsed
List all methods used in referenced not used functionality.

Namespace

Drupal\auditfiles

Code

public function auditfilesReferencedNotUsedGetFileData(array $row_data) {
  $connection = $this->connection;
  $query = 'SELECT * FROM {' . $row_data['table'] . '} WHERE ' . $row_data['column'] . ' = ' . $row_data['file_id'];
  $result = $connection
    ->query($query)
    ->fetchAll();
  $result = reset($result);
  if ($row_data['entity_type'] == 'node') {
    $url = Url::fromUri('internal:/node/' . $result->entity_id);
    $entity_id_display = Link::fromTextAndUrl('node/' . $result->entity_id, $url)
      ->toString();
  }
  else {
    $entity_id_display = $result->entity_id;
  }
  $row = [
    'file_id' => $result->{$row_data['column']},
    'entity_type' => $row_data['entity_type'],
    'bundle' => [
      'data' => $result->bundle,
      'hidden' => TRUE,
    ],
    'entity_id' => [
      'data' => $result->entity_id,
      'hidden' => TRUE,
    ],
    'entity_id_display' => $entity_id_display,
    'field' => $row_data['table'] . '.' . $row_data['column'],
    'table' => [
      'data' => $row_data['table'],
      'hidden' => TRUE,
    ],
    'uri' => 'No file object exists for this reference.',
    'filename' => [
      'data' => '',
      'hidden' => TRUE,
    ],
    'filemime' => '--',
    'filesize' => '--',
  ];

  // If there is a file in the file_managed table, add some of that
  // information to the row, too.
  $file_managed = $this->entityTypeManager
    ->getStorage('file')
    ->load($result->{$row_data['column']});
  if (!empty($file_managed)) {
    $row['uri'] = $file_managed
      ->getFileuri();
    $row['filename'] = [
      'data' => $file_managed
        ->getFilename(),
      'hidden' => TRUE,
    ];
    $row['filemime'] = $file_managed
      ->getMimeType();
    $row['filesize'] = $file_managed
      ->getSize();
  }
  return $row;
}