You are here

YieldRows.php in Migrate Source CSV 8.3

File

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

namespace Drupal\csv_source_yield_test\Plugin\migrate\source;

use Drupal\migrate_source_csv\Plugin\migrate\source\CSV;
use League\Csv\Reader;

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

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

  /**
   * Prepare a test row using yield.
   *
   * @param \League\Csv\Reader $reader
   *   The CSV reader.
   *
   * @codingStandardsIgnoreStart
   *
   * @return \Generator
   *   A generator with only the id value.
   *
   * @codingStandardsIgnoreEnd
   */
  public function getYield(Reader $reader) {
    foreach ($reader as $row) {
      $new_row = [];
      $new_row['id'] = $row['id'];
      (yield $new_row);
    }
  }

}

Classes

Namesort descending Description
YieldRows Yields each image and sku.