You are here

public function Image::prepareMediaEntityRow in Media Migration 8

Same name in this branch
  1. 8 src/Plugin/media_migration/file_entity/Image.php \Drupal\media_migration\Plugin\media_migration\file_entity\Image::prepareMediaEntityRow()
  2. 8 src/Plugin/media_migration/file/Image.php \Drupal\media_migration\Plugin\media_migration\file\Image::prepareMediaEntityRow()

Overrides FileBase::prepareMediaEntityRow

File

src/Plugin/media_migration/file_entity/Image.php, line 94

Class

Image
Image media migration plugin for local image media entities.

Namespace

Drupal\media_migration\Plugin\media_migration\file_entity

Code

public function prepareMediaEntityRow(Row $row, Connection $connection) : void {
  parent::prepareMediaEntityRow($row, $connection);
  $file_id = $row
    ->getSourceProperty('fid');

  // Add width and height source properties for image entities. These
  // properties only exist when the file_entity module is installed on the
  // source site.
  $width_and_height_statement = $connection
    ->select('file_metadata', 'fmd')
    ->fields('fmd', [
    'name',
    'value',
  ])
    ->condition('fmd.fid', $file_id)
    ->condition('fmd.name', [
    'width',
    'height',
  ], 'IN')
    ->execute()
    ->fetchAll(\PDO::FETCH_ASSOC);
  foreach ($width_and_height_statement as $result_row) {
    $row
      ->setSourceProperty($result_row['name'], unserialize($result_row['value']));
  }

  // Add alt and title properties from image type fields where the current
  // image is the file value.
  foreach ($this
    ->getImageData($connection, $file_id) as $data_key => $data_value) {
    $row
      ->setSourceProperty($data_key, $data_value);
  }
}