You are here

protected function FileDealerBase::getFileData in Media Migration 8

Returns display and description properties of the specified file.

Parameters

\Drupal\Core\Database\Connection $connection: The database connection of the source Drupal 7 instance.

string|int $file_id: The ID of the file.

Return value

array An array of those properties whose value is not empty.

2 calls to FileDealerBase::getFileData()
Fallback::prepareMediaEntityRow in src/Plugin/media_migration/file/Fallback.php
Image::prepareMediaEntityRow in src/Plugin/media_migration/file/Image.php

File

src/FileDealerBase.php, line 70

Class

FileDealerBase
Base implementation of file dealer plugins.

Namespace

Drupal\media_migration

Code

protected function getFileData(Connection $connection, $file_id) : array {
  foreach ($this
    ->getFileFieldData($connection) as $field_name) {
    $field_table_name = "field_data_{$field_name}";
    $data_query = $connection
      ->select($field_table_name, $field_name);
    $data_query
      ->addField($field_name, "{$field_name}_display", 'display');
    $data_query
      ->addField($field_name, "{$field_name}_description", 'description');
    $data_query
      ->condition("{$field_name}_fid", $file_id);
    if (!empty($results = $data_query
      ->execute()
      ->fetchAll(\PDO::FETCH_ASSOC))) {
      $result = reset($results);
      return array_filter($result);
    }
  }
  return [];
}