function ProfileField::prepareRow

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

Overrides SourcePluginBase::prepareRow

File

core/modules/user/src/Plugin/migrate/source/ProfileField.php, line 49

Class

ProfileField
Drupal 6/7 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);
}

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