You are here

public function DataStreamFromAsset::transform in farmOS 2.x

Performs the associated process.

Parameters

mixed $value: The value to be transformed.

\Drupal\migrate\MigrateExecutableInterface $migrate_executable: The migration in which this process is being executed.

\Drupal\migrate\Row $row: The row from the source to process. Normally, just transforming the value is adequate but very rarely you might need to change two columns at the same time or something like that.

string $destination_property: The destination property currently worked on. This is only used together with the $row above.

Return value

string|array The newly transformed value.

Overrides ProcessPluginBase::transform

File

modules/core/data_stream/src/Plugin/migrate/process/DataStreamFromAsset.php, line 24

Class

DataStreamFromAsset
Gets the first data stream associated with an asset.

Namespace

Drupal\data_stream\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {

  // Get the asset_id.
  $asset_id = $row
    ->getDestinationProperty('asset_id');

  // Bail if no asset ids are provided.
  if (empty($asset_id)) {
    return NULL;
  }

  // Load asset.
  $asset = \Drupal::entityTypeManager()
    ->getStorage('asset')
    ->load($asset_id);

  // Return the first data stream ID if one exists.
  if (!empty($asset) && $asset
    ->hasField('data_stream')) {
    $ids = array_column($asset->data_stream
      ->getValue(), 'target_id');
    return reset($ids);
  }
  return NULL;
}