You are here

YieldRows.php in Migrate Source CSV 8.2

File

tests/modules/source_plugin_yield_test/src/Plugin/migrate/source/YieldRows.php
View source
<?php

namespace Drupal\source_plugin_yield_test\Plugin\migrate\source;

use Drupal\migrate_source_csv\Plugin\migrate\source\CSV;

/**
 * Yields each image and sku.
 *
 * @MigrateSource(
 *   id = "yield_rows"
 * )
 */
class YieldRows extends CSV {

  /**
   * {@inheritdoc}
   */
  public function initializeIterator() {
    $file = parent::initializeIterator();
    return $this
      ->getYield($file);
  }

  /**
   * Prepare a test row using yield.
   *
   * @param \SplFileObject $file
   *   The source CSV file object.
   *
   * @codingStandardsIgnoreStart
   *
   * @return \Generator
   *   A new row with only the id value.
   *
   * @codingStandardsIgnoreEnd
   */
  public function getYield(\SplFileObject $file) {
    foreach ($file as $row_num => $row) {
      $new_row = [];
      $new_row['id'] = $row['id'];
      (yield $new_row);
    }
  }

}

Classes

Namesort descending Description
YieldRows Yields each image and sku.