You are here

public function BeerUser::prepareRow in Migrate Plus 8.3

Same name and namespace in other branches
  1. 8.5 migrate_example/src/Plugin/migrate/source/BeerUser.php \Drupal\migrate_example\Plugin\migrate\source\BeerUser::prepareRow()
  2. 8 migrate_example/src/Plugin/migrate/source/BeerUser.php \Drupal\migrate_example\Plugin\migrate\source\BeerUser::prepareRow()
  3. 8.2 migrate_example/src/Plugin/migrate/source/BeerUser.php \Drupal\migrate_example\Plugin\migrate\source\BeerUser::prepareRow()
  4. 8.4 migrate_example/src/Plugin/migrate/source/BeerUser.php \Drupal\migrate_example\Plugin\migrate\source\BeerUser::prepareRow()

Adds additional data to the row.

Parameters

\Drupal\migrate\Row $row: The row object.

Return value

bool FALSE if this row needs to be skipped.

Overrides SourcePluginBase::prepareRow

File

migrate_example/src/Plugin/migrate/source/BeerUser.php, line 60

Class

BeerUser
Source plugin for beer user accounts.

Namespace

Drupal\migrate_example\Plugin\migrate\source

Code

public function prepareRow(Row $row) {

  /**
   * prepareRow() is the most common place to perform custom run-time
   * processing that isn't handled by an existing process plugin. It is called
   * when the raw data has been pulled from the source, and provides the
   * opportunity to modify or add to that data, creating the canonical set of
   * source data that will be fed into the processing pipeline.
   *
   * In our particular case, the list of a user's favorite beers is a pipe-
   * separated list of beer IDs. The processing pipeline deals with arrays
   * representing multi-value fields naturally, so we want to explode that
   * string to an array of individual beer IDs.
   */
  if ($value = $row
    ->getSourceProperty('beers')) {
    $row
      ->setSourceProperty('beers', explode('|', $value));
  }

  /**
   * Always call your parent! Essential processing is performed in the base
   * class. Be mindful that prepareRow() returns a boolean status - if FALSE
   * that indicates that the item being processed should be skipped. Unless
   * we're deciding to skip an item ourselves, let the parent class decide.
   */
  return parent::prepareRow($row);
}