You are here

protected function FileBase::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.

1 call to FileBase::getFileData()
FileBase::prepareMediaEntityRow in src/Plugin/media_migration/file_entity/FileBase.php

File

src/Plugin/media_migration/file_entity/FileBase.php, line 92

Class

FileBase
Abstract plugin class for file-based media migration source plugins.

Namespace

Drupal\media_migration\Plugin\media_migration\file_entity

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 [];
}