You are here

public function CommerceAttributeHandlerSetting::transform in Commerce Migrate 8.2

Same name and namespace in other branches
  1. 3.1.x modules/commerce/src/Plugin/migrate/process/commerce1/CommerceAttributeHandlerSetting.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\CommerceAttributeHandlerSetting::transform()
  2. 3.0.x modules/commerce/src/Plugin/migrate/process/commerce1/CommerceAttributeHandlerSetting.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\CommerceAttributeHandlerSetting::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/commerce/src/Plugin/migrate/process/commerce1/CommerceAttributeHandlerSetting.php, line 22

Class

CommerceAttributeHandlerSetting
Adjusts the fields settings for attributes.

Namespace

Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1

Code

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

  // If this is an attribute field, add the handler_settings.
  if ('commerce_product' === $row
    ->getSourceProperty('entity_type') && 'taxonomy_term_reference' === $row
    ->getSourceProperty('type') && 'options_select' === $row
    ->getSourceProperty('widget')['type']) {
    $new_handler_settings['target_bundles'][] = $row
      ->getSourceProperty('bundle');
    $settings = $row
      ->getDestinationProperty('settings');
    $handler_settings = isset($settings['handler_settings']) ? $settings['handler_settings'] : [];
    return array_merge($handler_settings, $new_handler_settings);
  }
  else {
    throw new MigrateSkipProcessException();
  }
}