You are here

class ProductTab in Commerce Migrate 8.2

Same name and namespace in other branches
  1. 3.1.x modules/csv_example/src/Plugin/migrate/source/ProductTab.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\ProductTab
  2. 3.0.x modules/csv_example/src/Plugin/migrate/source/ProductTab.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\ProductTab

Yields values for each product tab paragraph.

There are two set of columns for the paragraph product tab 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_tab for the column names.

Plugin annotation


@MigrateSource(
  id = "csv_example_product_tab"
)

Hierarchy

  • class \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\ProductTab extends \Drupal\migrate_source_csv\Plugin\migrate\source\CSV

Expanded class hierarchy of ProductTab

File

modules/csv_example/src/Plugin/migrate/source/ProductTab.php, line 18

Namespace

Drupal\commerce_migrate_csv_example\Plugin\migrate\source
View source
class ProductTab extends CSV {

  /**
   * {@inheritdoc}
   */
  public function initializeIterator() {
    $file = parent::initializeIterator();
    return $this
      ->getYield($file);
  }

  /**
   * Prepares one row per tab paragraph values 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) {
      for ($i = 1; $i < 3; $i++) {
        if (!empty($row["tab_title{$i}"]) || !empty($row["tab_content{$i}"]) || !empty($row["tab_content{$i}"])) {
          $new_row = $row;
          $new_row['tab_title'] = trim($row["tab_title{$i}"]);
          $new_row['tab_content'] = trim($row["tab_content{$i}"]);
          $new_row['tab_cta'] = trim($row["tab_cta{$i}"]);
          (yield $new_row);
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ProductTab::getYield public function Prepares one row per tab paragraph values in the source row.
ProductTab::initializeIterator public function