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/ubercart/src/Plugin/migrate/source/uc6/ViewMode.php \Drupal\commerce_migrate_ubercart\Plugin\migrate\source\uc6\ViewMode::initializeIterator()
  2. 3.0.x modules/ubercart/src/Plugin/migrate/source/uc6/ViewMode.php \Drupal\commerce_migrate_ubercart\Plugin\migrate\source\uc6\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/ubercart/src/Plugin/migrate/source/uc6/ViewMode.php, line 24

Class

ViewMode
The view mode source.

Namespace

Drupal\commerce_migrate_ubercart\Plugin\migrate\source\uc6

Code

protected function initializeIterator() {

  // Copy the iterator from node/src/Plugin/migrate/uc6/ViewMode so that the
  // type_name can be added to the row and used in the prepareRow event.
  $rows = [];
  $result = $this
    ->prepareQuery()
    ->execute();
  while ($field_row = $result
    ->fetchAssoc()) {
    $field_row['display_settings'] = unserialize($field_row['display_settings']);
    foreach ($this
      ->getViewModes() as $view_mode) {

      // Append to the return value if the row has display settings for this
      // view mode and the view mode is neither hidden nor excluded.
      // @see \Drupal\field\Plugin\migrate\source\uc6\FieldInstancePerViewMode::initializeIterator()
      if (isset($field_row['display_settings'][$view_mode]) && $field_row['display_settings'][$view_mode]['format'] != 'hidden' && empty($field_row['display_settings'][$view_mode]['exclude'])) {
        if (!isset($rows[$view_mode])) {
          $rows[$view_mode]['entity_type'] = 'node';
          $rows[$view_mode]['view_mode'] = $view_mode;
          $rows[$view_mode]['type_name'] = $field_row['type_name'];
        }
      }
    }
  }
  return new \ArrayIterator($rows);
}