You are here

protected function ContentImporter::processReferences in Commerce Demo 8

Same name and namespace in other branches
  1. 8.2 src/ContentImporter.php \Drupal\commerce_demo\ContentImporter::processReferences()

Processes reference values before importing.

Parameters

array $values: The entity values.

\Drupal\Core\Entity\EntityInterface $entity: The entity.

string $field_name: The name of the field containing the references. Currently supports 'variations' and 'coupons'.

Return value

array The processed product values.

1 call to ContentImporter::processReferences()
ContentImporter::importEntity in src/ContentImporter.php
Imports a given entity.

File

src/ContentImporter.php, line 228

Class

ContentImporter
Defines the content importer.

Namespace

Drupal\commerce_demo

Code

protected function processReferences(array $values, EntityInterface $entity, $field_name) {
  $ids = [];
  foreach ($values[$field_name] as $uuid => $entity_values) {
    $entity_values['uuid'] = $uuid;
    if ($field_name == 'variations') {
      $entity_type_id = 'commerce_product_variation';
    }
    elseif ($field_name == 'coupons') {
      $entity_type_id = 'commerce_promotion_coupon';
    }
    else {
      return $values;
    }
    $imported_entity = $this
      ->importEntity($entity_type_id, $entity_values);
    $ids[] = $imported_entity
      ->id();
  }
  $values[$field_name] = $ids;
  return $values;
}