You are here

protected function ViewMode::initializeIterator in Commerce Migrate 8.2

Same name in this branch
  1. 8.2 modules/ubercart/src/Plugin/migrate/source/uc7/ViewMode.php \Drupal\commerce_migrate_ubercart\Plugin\migrate\source\uc7\ViewMode::initializeIterator()
  2. 8.2 modules/ubercart/src/Plugin/migrate/source/uc6/ViewMode.php \Drupal\commerce_migrate_ubercart\Plugin\migrate\source\uc6\ViewMode::initializeIterator()
  3. 8.2 modules/commerce/src/Plugin/migrate/source/commerce1/ViewMode.php \Drupal\commerce_migrate_commerce\Plugin\migrate\source\commerce1\ViewMode::initializeIterator()
Same name and namespace in other branches
  1. 3.1.x modules/commerce/src/Plugin/migrate/source/commerce1/ViewMode.php \Drupal\commerce_migrate_commerce\Plugin\migrate\source\commerce1\ViewMode::initializeIterator()
  2. 3.0.x modules/commerce/src/Plugin/migrate/source/commerce1/ViewMode.php \Drupal\commerce_migrate_commerce\Plugin\migrate\source\commerce1\ViewMode::initializeIterator()

Initializes the iterator with the source data.

Return value

\Iterator Returns an iteratable object of data for this source.

Overrides ViewMode::initializeIterator

File

modules/commerce/src/Plugin/migrate/source/commerce1/ViewMode.php, line 23

Class

ViewMode
The view mode source class.

Namespace

Drupal\commerce_migrate_commerce\Plugin\migrate\source\commerce1

Code

protected function initializeIterator() {
  $instances = parent::initializeIterator();
  $rows = [];
  foreach ($instances
    ->getArrayCopy() as $instance) {
    $data = unserialize($instance['data']);
    $instance['commerce1_entity_type'] = $instance['entity_type'];
    foreach (array_keys($data['display']) as $view_mode) {
      $key = $instance['entity_type'] . '.' . $view_mode;
      $rows[$key] = array_merge($instance, [
        'view_mode' => $view_mode,
      ]);

      // If this is a node view mode, then it is also a product display view
      // mode. Create a new row for product display.
      if ($instance['entity_type'] === 'node') {
        $new_row = $instance;
        $key = 'product_display.' . $view_mode;

        // The entity_type is a sourceId and this entity_type does not exist
        // in the source database. By adding it here, it allows for the
        // creation of two rows without using entity_generate which, when
        // used, means that rollbacks will not work correctly because the
        // generated entity is not in the map table.
        $new_row['entity_type'] = 'product_display';
        $new_row['commerce1_entity_type'] = 'product_display';
        $rows[$key] = array_merge($new_row, [
          'view_mode' => $view_mode,
        ]);
      }
    }
  }
  return new \ArrayIterator($rows);
}