You are here

public function Recipe61::prepareRow in Recipe 8.2

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

src/Plugin/migrate/source/recipe61/Recipe61.php, line 54

Class

Recipe61
Drupal 6 recipe source from database.

Namespace

Drupal\recipe\Plugin\migrate\source\recipe61

Code

public function prepareRow(Row $row) {

  // Select the ingredient reference data and add it to the row.
  $query = $this
    ->select('recipe_node_ingredient', 'i');
  $query
    ->leftJoin('recipe_unit', 'ru', 'i.unit_id = ru.id');
  $query
    ->fields('i', [
    'quantity',
    'ingredient_id',
    'weight',
    'note',
  ])
    ->fields('ru', [
    'name',
  ])
    ->condition('nid', $row
    ->getSourceProperty('nid'))
    ->orderBy('weight', 'ASC');
  $results = $query
    ->execute();
  $ingredients = [];
  foreach ($results as $result) {

    // Check for updated unit names.
    $result['name'] = strtolower($result['name']);
    $result['unit_key'] = isset(self::CHANGED_UNITS[$result['name']]) ? self::CHANGED_UNITS[$result['name']] : $result['name'];
    $ingredients[] = $result;
  }
  $row
    ->setSourceProperty('ingredients', $ingredients);

  // Make sure we always have a translation set.
  if ($row
    ->getSourceProperty('tnid') == 0) {
    $row
      ->setSourceProperty('tnid', $row
      ->getSourceProperty('nid'));
  }
  return parent::prepareRow($row);
}