You are here

protected function MediaDealerBase::getImageData in Media Migration 8

Returns alt, title, with and height 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 MediaDealerBase::getImageData()
Image::prepareMediaEntityRow in src/Plugin/media_migration/file/Image.php
Image::prepareMediaEntityRow in src/Plugin/media_migration/file_entity/Image.php

File

src/MediaDealerBase.php, line 409

Class

MediaDealerBase
Base implementation of media dealer plugins.

Namespace

Drupal\media_migration

Code

protected function getImageData(Connection $connection, $file_id) : array {
  foreach ($this
    ->getImageFieldData($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}_alt", 'alt');
    $data_query
      ->addField($field_name, "{$field_name}_title", 'title');
    $data_query
      ->addField($field_name, "{$field_name}_height", 'height');
    $data_query
      ->addField($field_name, "{$field_name}_width", 'width');
    $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 [];
}