public function Image::getYield in Commerce Migrate 8.2
Same name in this branch
- 8.2 modules/csv_example/src/Plugin/migrate/source/Image.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\Image::getYield()
- 8.2 modules/magento/src/Plugin/migrate/source/magento2/Image.php \Drupal\commerce_migrate_magento\Plugin\migrate\source\magento2\Image::getYield()
Same name and namespace in other branches
- 3.1.x modules/csv_example/src/Plugin/migrate/source/Image.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\Image::getYield()
- 3.0.x modules/csv_example/src/Plugin/migrate/source/Image.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\Image::getYield()
Prepare one row per image file 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 Image::getYield()
- Image::initializeIterator in modules/
csv_example/ src/ Plugin/ migrate/ source/ Image.php
File
- modules/
csv_example/ src/ Plugin/ migrate/ source/ Image.php, line 42
Class
- Image
- Yields each image and sku.
Namespace
Drupal\commerce_migrate_csv_example\Plugin\migrate\sourceCode
public function getYield(\Generator $file) {
foreach ($file as $row) {
if (!empty($row['sku'])) {
// There is a SKU so let's check for images.
$new_row = [];
$new_row['sku'] = trim($row['sku']);
// Product variation images.
for ($i = 1; $i < 4; $i++) {
$new_row['image'] = trim($row["image{$i}"]);
if (!empty($new_row['image'])) {
(yield $new_row);
}
}
// Video thumbnails.
for ($i = 1; $i < 4; $i++) {
$new_row['image'] = trim($row["thumbnail{$i}"]);
if (!empty($new_row['image'])) {
(yield $new_row);
}
}
// Call to action images.
for ($i = 1; $i < 3; $i++) {
$new_row['image'] = trim($row["cta_image{$i}"]);
if (!empty($new_row['image'])) {
(yield $new_row);
}
}
}
}
}