You are here

public function AttributeDestination::transform in Commerce Migrate 8.2

Same name and namespace in other branches
  1. 3.1.x modules/csv_example/src/Plugin/migrate/process/AttributeDestination.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\process\AttributeDestination::transform()
  2. 3.0.x modules/csv_example/src/Plugin/migrate/process/AttributeDestination.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\process\AttributeDestination::transform()

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/csv_example/src/Plugin/migrate/process/AttributeDestination.php, line 51

Class

AttributeDestination
Sets attributes on the destination.

Namespace

Drupal\commerce_migrate_csv_example\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  if (is_array($value)) {
    $count = count($value);
    if (!($count & 1)) {
      for ($i = 0; $i < $count; $i = $i + 2) {
        if (!empty($value[$i]) && !empty($value[$i + 1])) {
          $field_name = 'attribute_' . $value[$i];
          $field_name = substr($field_name, 0, 32);
          $row
            ->setDestinationProperty($field_name, $value[$i + 1]);
        }
      }
    }
    else {
      throw new MigrateException('There must be an even number of input values.');
    }
  }
}