function ProfileFieldValues::prepareRow

Same name in other branches
  1. 9 core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldValues.php \Drupal\user\Plugin\migrate\source\d6\ProfileFieldValues::prepareRow()
  2. 8.9.x core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldValues.php \Drupal\user\Plugin\migrate\source\d6\ProfileFieldValues::prepareRow()
  3. 10 core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldValues.php \Drupal\user\Plugin\migrate\source\d6\ProfileFieldValues::prepareRow()

Overrides SourcePluginBase::prepareRow

File

core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldValues.php, line 37

Class

ProfileFieldValues
Drupal 6 profile fields values source from database.

Namespace

Drupal\user\Plugin\migrate\source\d6

Code

public function prepareRow(Row $row) {
    // Find profile values for this row.
    $query = $this->select('profile_values', 'pv')
        ->fields('pv', [
        'fid',
        'value',
    ]);
    $query->leftJoin('profile_fields', 'pf', '[pf].[fid] = [pv].[fid]');
    $query->fields('pf', [
        'name',
        'type',
    ]);
    $query->condition('uid', $row->getSourceProperty('uid'));
    $results = $query->execute();
    foreach ($results as $profile_value) {
        // Check special case for date. We need to unserialize.
        if ($profile_value['type'] == 'date') {
            $date = unserialize($profile_value['value']);
            $date = date('Y-m-d', mktime(0, 0, 0, $date['month'], $date['day'], $date['year']));
            $row->setSourceProperty($profile_value['name'], [
                'value' => $date,
            ]);
        }
        elseif ($profile_value['type'] == 'list') {
            // Explode by newline and comma.
            $row->setSourceProperty($profile_value['name'], preg_split("/[\r\n,]+/", $profile_value['value']));
        }
        else {
            $row->setSourceProperty($profile_value['name'], [
                $profile_value['value'],
            ]);
        }
    }
    return parent::prepareRow($row);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.