You are here

public function FileEntityFieldInstanceSettings::transform in Media Migration 8

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

src/Plugin/migrate/process/FileEntityFieldInstanceSettings.php, line 20

Class

FileEntityFieldInstanceSettings
Configure field instance settings for file entity fields.

Namespace

Drupal\media_migration\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  $type = $row
    ->getSourceProperty('type');
  if ($type == 'file_entity') {
    $existing_media_type_ids = array_keys($this
      ->getExistingMediaTypeData());
    $predicted_media_type_ids = array_keys($this
      ->getPredictedMediaTypeData());
    $media_type_ids = array_unique(array_merge($existing_media_type_ids, $predicted_media_type_ids));
    $widget_settings = $row
      ->getSourceProperty('widget');
    $target_bundles = !empty($widget_settings['settings']['allowed_types']) ? array_filter($widget_settings['settings']['allowed_types']) : [];

    // In Drupal 7, when no media types are explicitly enabled on this field,
    // that means that every media type is allowed. In Drupal 8|9, this
    // feature is not available anymore: "target_bundles" cannot be empty.
    $value['handler_settings']['target_bundles'] = !empty($target_bundles) ? $target_bundles : array_combine($media_type_ids, $media_type_ids);
  }
  return $value;
}