You are here

public function Field::prepareRow in Drupal 8

Same name in this branch
  1. 8 core/modules/field/src/Plugin/migrate/source/d6/Field.php \Drupal\field\Plugin\migrate\source\d6\Field::prepareRow()
  2. 8 core/modules/field/src/Plugin/migrate/source/d7/Field.php \Drupal\field\Plugin\migrate\source\d7\Field::prepareRow()
Same name and namespace in other branches
  1. 9 core/modules/field/src/Plugin/migrate/source/d6/Field.php \Drupal\field\Plugin\migrate\source\d6\Field::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

core/modules/field/src/Plugin/migrate/source/d6/Field.php, line 64

Class

Field
Drupal 6 field source from database.

Namespace

Drupal\field\Plugin\migrate\source\d6

Code

public function prepareRow(Row $row) {

  // The instance widget_type helps determine what D8 field type we'll use.
  // Identify the distinct widget_types being used in D6.
  $widget_types = $this
    ->select('content_node_field_instance', 'cnfi')
    ->fields('cnfi', [
    'widget_type',
  ])
    ->condition('field_name', $row
    ->getSourceProperty('field_name'))
    ->distinct()
    ->orderBy('widget_type')
    ->execute()
    ->fetchCol();

  // Arbitrarily use the first widget_type - if there are multiples, let the
  // migrator know.
  $row
    ->setSourceProperty('widget_type', $widget_types[0]);
  if (count($widget_types) > 1) {
    $this->migration
      ->getIdMap()
      ->saveMessage([
      'field_name' => $row
        ->getSourceProperty('field_name'),
    ], $this
      ->t('Widget types @types are used in Drupal 6 field instances: widget type @selected_type applied to the Drupal 8 base field', [
      '@types' => implode(', ', $widget_types),
      '@selected_type' => $widget_types[0],
    ]));
  }

  // Unserialize data.
  $global_settings = unserialize($row
    ->getSourceProperty('global_settings'));
  $db_columns = unserialize($row
    ->getSourceProperty('db_columns'));
  $row
    ->setSourceProperty('global_settings', $global_settings);
  $row
    ->setSourceProperty('db_columns', $db_columns);
  return parent::prepareRow($row);
}