You are here

class CsvCell in Commerce Migrate 3.1.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/migrate/source/csv/CsvCell.php \Drupal\commerce_migrate\Plugin\migrate\source\csv\CsvCell
  2. 3.0.x src/Plugin/migrate/source/csv/CsvCell.php \Drupal\commerce_migrate\Plugin\migrate\source\csv\CsvCell

Yields source values from a cell that is a comma separated list.

Use when the migration needs only one value from the source CSV and that value is itself a comma separated list. The source keys should contain one key only and it is also used as the key in the output row.

Plugin annotation


@MigrateSource(
  id = "commerce_migrate_csvcell"
)

Hierarchy

  • class \Drupal\commerce_migrate\Plugin\migrate\source\csv\CsvCell extends \Drupal\migrate_source_csv\Plugin\migrate\source\CSV

Expanded class hierarchy of CsvCell

File

src/Plugin/migrate/source/csv/CsvCell.php, line 18

Namespace

Drupal\commerce_migrate\Plugin\migrate\source\csv
View source
class CsvCell extends CSV {

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

  /**
   * Prepare one row per taxonomy term field in the source.
   *
   * @param \Generator $file
   *   The source CSV file object.
   *
   * @codingStandardsIgnoreStart
   *
   * @return \Generator
   *   A new row with one taxonomy term.
   *
   * @codingStandardsIgnoreEnd
   */
  public function getYield(\Generator $file) {
    $key = reset($this->configuration['ids']);
    foreach ($file as $row) {
      $new_row = [];
      $tags = explode(',', $row['Tags']);
      foreach ($tags as $tag) {
        $new_row[$key] = trim($tag);
        (yield $new_row);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CsvCell::getYield public function Prepare one row per taxonomy term field in the source.
CsvCell::initializeIterator public function