class Image in Commerce Migrate 3.1.x
Same name in this branch
- 3.1.x modules/csv_example/src/Plugin/migrate/source/Image.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\Image
- 3.1.x modules/magento/src/Plugin/migrate/source/magento2/Image.php \Drupal\commerce_migrate_magento\Plugin\migrate\source\magento2\Image
Same name and namespace in other branches
- 8.2 modules/csv_example/src/Plugin/migrate/source/Image.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\Image
- 3.0.x modules/csv_example/src/Plugin/migrate/source/Image.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\Image
Yields each image and sku.
There are several columns for image names in the example source. Three are images of the product variation, three are for thumbnails for videos, and two are for the CTA image. Create a new row for image and SKU where both are non empty. See import_image for the column names.
Plugin annotation
@MigrateSource(
id = "csv_example_image"
)
Hierarchy
- class \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\Image extends \Drupal\migrate_source_csv\Plugin\migrate\source\CSV
Expanded class hierarchy of Image
4 string references to 'Image'
- FieldInstanceTest::testFieldInstances in modules/
commerce/ tests/ src/ Kernel/ Migrate/ commerce1/ FieldInstanceTest.php - Tests migrating D7 field instances to field_config entities.
- MigrateUpgradeReviewPageTest::getAvailablePaths in modules/
ubercart/ tests/ src/ Functional/ uc7/ MigrateUpgradeReviewPageTest.php - Gets the available upgrade paths.
- MigrateUpgradeReviewPageTest::getAvailablePaths in modules/
commerce/ tests/ src/ Functional/ commerce1/ MigrateUpgradeReviewPageTest.php - Gets the available upgrade paths.
- MigrateUpgradeReviewPageTest::getMissingPaths in modules/
ubercart/ tests/ src/ Functional/ uc6/ MigrateUpgradeReviewPageTest.php - Gets the missing upgrade paths.
File
- modules/
csv_example/ src/ Plugin/ migrate/ source/ Image.php, line 19
Namespace
Drupal\commerce_migrate_csv_example\Plugin\migrate\sourceView source
class Image extends CSV {
/**
* {@inheritdoc}
*/
public function initializeIterator() {
$file = parent::initializeIterator();
return $this
->getYield($file);
}
/**
* Prepare one row per image file in the source row.
*
* @param \Generator $file
* The source CSV file object.
*
* @codingStandardsIgnoreStart
*
* @return \Generator
* A new row, one for each filename in the source image column.
*
* @codingStandardsIgnoreEnd
*/
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);
}
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Image:: |
public | function | Prepare one row per image file in the source row. | |
Image:: |
public | function |