You are here

public function Attribute::getYield in Commerce Migrate 3.1.x

Same name and namespace in other branches
  1. 8.2 modules/csv_example/src/Plugin/migrate/source/Attribute.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\Attribute::getYield()
  2. 3.0.x modules/csv_example/src/Plugin/migrate/source/Attribute.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\Attribute::getYield()

Prepares one row per attribute pair in the source row.

@codingStandardsIgnoreStart

@codingStandardsIgnoreEnd

Parameters

\Generator $file: The source CSV file object.

Return value

\Generator A new row, one for each filename in the source image column.

1 call to Attribute::getYield()
Attribute::initializeIterator in modules/csv_example/src/Plugin/migrate/source/Attribute.php

File

modules/csv_example/src/Plugin/migrate/source/Attribute.php, line 41

Class

Attribute
Yields each attribute name and value pair.

Namespace

Drupal\commerce_migrate_csv_example\Plugin\migrate\source

Code

public function getYield(\Generator $file) {
  foreach ($file as $row) {
    $new_row = [];
    for ($i = 1; $i < 5; $i++) {
      $new_row['attribute_name'] = trim($row["attribute_name{$i}"]);
      $new_row['attribute_value'] = trim($row["attribute_value{$i}"]);
      if (!empty($new_row['attribute_name']) && !empty($new_row['attribute_value'])) {
        if ($this
          ->rowUnique($new_row)) {
          (yield $new_row);
        }
      }
    }
  }
}