You are here

public function ImageStyleMappings::transform in Drupal 9

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

core/modules/responsive_image/src/Plugin/migrate/process/ImageStyleMappings.php, line 22

Class

ImageStyleMappings
Transforms image style mappings.

Namespace

Drupal\responsive_image\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  if (!is_array($value)) {
    throw new MigrateException(sprintf('Input should be an array for destination %s', $destination_property));
  }
  list($mappings, $breakpoint_group) = $value;
  $new_value = [];
  foreach ($mappings as $mapping_id => $mapping) {

    // The id is in the key with the form
    // "breakpoints.theme.my_theme_id.image_style_machine_name". We want the
    // identifier after the last period.
    preg_match('/\\.([a-z0-9_]+)$/', $mapping_id, $matches);
    foreach ($mapping as $multiplier => $multiplier_settings) {
      if ($multiplier_settings['mapping_type'] == '_none') {
        continue;
      }
      $image_style = [
        'breakpoint_id' => $breakpoint_group . '.' . $matches[1],
        'multiplier' => $multiplier,
        'image_mapping_type' => $multiplier_settings['mapping_type'],
        'image_mapping' => $this
          ->getMultiplierSettings($multiplier_settings),
      ];
      $new_value[] = $image_style;
    }
  }
  return $new_value;
}