class ProductCta in Commerce Migrate 3.0.x
Same name and namespace in other branches
- 8.2 modules/csv_example/src/Plugin/migrate/source/ProductCta.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\ProductCta
- 3.1.x modules/csv_example/src/Plugin/migrate/source/ProductCta.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\ProductCta
Yields values for each product CTA paragraph.
There are two set of columns for the paragraph product CTA in each row of the example source. Create a new row for each set where at least one value of the set is non empty. See import_cta for the column names.
Plugin annotation
@MigrateSource(
id = "csv_example_product_cta"
)
Hierarchy
- class \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\ProductCta extends \Drupal\migrate_source_csv\Plugin\migrate\source\CSV
Expanded class hierarchy of ProductCta
File
- modules/
csv_example/ src/ Plugin/ migrate/ source/ ProductCta.php, line 18
Namespace
Drupal\commerce_migrate_csv_example\Plugin\migrate\sourceView source
class ProductCta extends CSV {
/**
* {@inheritdoc}
*/
public function initializeIterator() {
$file = parent::initializeIterator();
return $this
->getYield($file);
}
/**
* Prepare one row per CTA paragraph in the source row.
*
* @param \Generator $file
* The source CSV file object.
*
* @codingStandardsIgnoreStart
*
* @return \Generator
* A new row, one for each CTA paragraph field.
*
* @codingStandardsIgnoreEnd
*/
public function getYield(\Generator $file) {
foreach ($file as $row) {
for ($i = 1; $i < 3; $i++) {
if (!empty($row["cta_title{$i}"]) || !empty($row["cta_link{$i}"]) || !empty($row["cta_image{$i}"])) {
$new_row = $row;
$new_row['cta_title'] = trim($row["cta_title{$i}"]);
$new_row['cta_link'] = trim($row["cta_link{$i}"]);
$new_row['cta_image'] = trim($row["cta_image{$i}"]);
(yield $new_row);
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ProductCta:: |
public | function | Prepare one row per CTA paragraph in the source row. | |
ProductCta:: |
public | function |