ProductCta.php in Commerce Migrate 8.2
File
modules/csv_example/src/Plugin/migrate/source/ProductCta.php
View source
<?php
namespace Drupal\commerce_migrate_csv_example\Plugin\migrate\source;
use Drupal\migrate_source_csv\Plugin\migrate\source\CSV;
class ProductCta extends CSV {
public function initializeIterator() {
$file = parent::initializeIterator();
return $this
->getYield($file);
}
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);
}
}
}
}
}
Classes
Name |
Description |
ProductCta |
Yields values for each product CTA paragraph. |