3 namespace Drupal\user\Plugin\migrate\source;
5 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
6 use Drupal\migrate\Row;
9 * Profile field source from database.
12 * id = "profile_field",
13 * source_module = "profile"
16 class ProfileField extends DrupalSqlBase {
19 * The source table containing profile field info.
23 protected $fieldTable;
26 * The source table containing the profile values.
30 protected $valueTable;
35 public function query() {
36 if (empty($this->fieldTable) || empty($this->valueTable)) {
37 if ($this->getModuleSchemaVersion('system') >= 7000) {
38 $this->fieldTable = 'profile_field';
39 $this->valueTable = 'profile_value';
42 $this->fieldTable = 'profile_fields';
43 $this->valueTable = 'profile_values';
46 return $this->select($this->fieldTable, 'pf')->fields('pf');
52 public function prepareRow(Row $row) {
53 if ($row->getSourceProperty('type') == 'selection') {
54 // Get the current options.
55 $current_options = preg_split("/[\r\n]+/", $row->getSourceProperty('options'));
56 // Select the list values from the profile_values table to ensure we get
57 // them all since they can get out of sync with profile_fields.
58 $options = $this->select($this->valueTable, 'pv')
60 ->fields('pv', ['value'])
61 ->condition('fid', $row->getSourceProperty('fid'))
64 $options = array_merge($current_options, $options);
65 // array_combine() takes care of any duplicates options.
66 $row->setSourceProperty('options', array_combine($options, $options));
69 if ($row->getSourceProperty('type') == 'checkbox') {
70 // D6 profile checkboxes values are always 0 or 1 (with no labels), so we
71 // need to create two label-less options that will get 0 and 1 for their
73 $row->setSourceProperty('options', [NULL, NULL]);
76 return parent::prepareRow($row);
82 public function fields() {
84 'fid' => $this->t('Primary Key: Unique profile field ID.'),
85 'title' => $this->t('Title of the field shown to the end user.'),
86 'name' => $this->t('Internal name of the field used in the form HTML and URLs.'),
87 'explanation' => $this->t('Explanation of the field to end users.'),
88 'category' => $this->t('Profile category that the field will be grouped under.'),
89 'page' => $this->t("Title of page used for browsing by the field's value"),
90 'type' => $this->t('Type of form field.'),
91 'weight' => $this->t('Weight of field in relation to other profile fields.'),
92 'required' => $this->t('Whether the user is required to enter a value. (0 = no, 1 = yes)'),
93 'register' => $this->t('Whether the field is visible in the user registration form. (1 = yes, 0 = no)'),
94 'visibility' => $this->t('The level of visibility for the field. (0 = hidden, 1 = private, 2 = public on profile but not member list pages, 3 = public on profile and list pages)'),
95 'autocomplete' => $this->t('Whether form auto-completion is enabled. (0 = disabled, 1 = enabled)'),
96 'options' => $this->t('List of options to be used in a list selection field.'),
103 public function getIds() {
104 $ids['fid']['type'] = 'integer';