You are here

public function ProfileField::prepareRow in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/user/src/Plugin/migrate/source/ProfileField.php \Drupal\user\Plugin\migrate\source\ProfileField::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/user/src/Plugin/migrate/source/ProfileField.php, line 44

Class

ProfileField
Profile field source from database.

Namespace

Drupal\user\Plugin\migrate\source

Code

public function prepareRow(Row $row) {
  if ($row
    ->getSourceProperty('type') == 'selection') {

    // Get the current options.
    $current_options = preg_split("/[\r\n]+/", $row
      ->getSourceProperty('options'));

    // Select the list values from the profile_values table to ensure we get
    // them all since they can get out of sync with profile_fields.
    $options = $this
      ->select($this->valueTable, 'pv')
      ->distinct()
      ->fields('pv', [
      'value',
    ])
      ->condition('fid', $row
      ->getSourceProperty('fid'))
      ->execute()
      ->fetchCol();
    $options = array_merge($current_options, $options);

    // array_combine() takes care of any duplicates options.
    $row
      ->setSourceProperty('options', array_combine($options, $options));
  }
  if ($row
    ->getSourceProperty('type') == 'checkbox') {

    // D6 profile checkboxes values are always 0 or 1 (with no labels), so we
    // need to create two label-less options that will get 0 and 1 for their
    // keys.
    $row
      ->setSourceProperty('options', [
      NULL,
      NULL,
    ]);
  }
  return parent::prepareRow($row);
}