class ProfileFieldValues
Same name and namespace in other branches
- 11.x core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldValues.php \Drupal\user\Plugin\migrate\source\d6\ProfileFieldValues
Drupal 6 profile fields values source from database.
For available configuration keys, refer to the parent classes.
Plugin annotation
@MigrateSource(
id = "d6_profile_field_values",
source_module = "profile"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
- class \Drupal\migrate\Plugin\migrate\source\SourcePluginBase extends \Drupal\migrate\Plugin\MigrateSourceInterface, \Drupal\migrate\Event\RollbackAwareInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\migrate\Plugin\migrate\source\SqlBase extends \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\migrate\Plugin\RequirementsInterface implements \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
- class \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase extends \Drupal\Component\Plugin\DependentPluginInterface uses \Drupal\Core\Entity\DependencyTrait implements \Drupal\migrate\Plugin\migrate\source\SqlBase
- class \Drupal\user\Plugin\migrate\source\d6\ProfileFieldValues implements \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
- class \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase extends \Drupal\Component\Plugin\DependentPluginInterface uses \Drupal\Core\Entity\DependencyTrait implements \Drupal\migrate\Plugin\migrate\source\SqlBase
- class \Drupal\migrate\Plugin\migrate\source\SqlBase extends \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\migrate\Plugin\RequirementsInterface implements \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
- class \Drupal\migrate\Plugin\migrate\source\SourcePluginBase extends \Drupal\migrate\Plugin\MigrateSourceInterface, \Drupal\migrate\Event\RollbackAwareInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of ProfileFieldValues
See also
\Drupal\migrate\Plugin\migrate\source\SqlBase
\Drupal\migrate\Plugin\migrate\source\SourcePluginBase
File
-
core/
modules/ user/ src/ Plugin/ migrate/ source/ d6/ ProfileFieldValues.php, line 21
Namespace
Drupal\user\Plugin\migrate\source\d6View source
class ProfileFieldValues extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('profile_values', 'pv')
->distinct()
->fields('pv', [
'uid',
]);
return $query;
}
/**
* {@inheritdoc}
*/
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);
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = [
'fid' => $this->t('Unique profile field ID.'),
'uid' => $this->t('The user Id.'),
'value' => $this->t('The value for this field.'),
];
$query = $this->select('profile_values', 'pv')
->fields('pv', [
'fid',
'value',
]);
$query->leftJoin('profile_fields', 'pf', '[pf].[fid] = [pv].[fid]');
$query->fields('pf', [
'name',
'title',
]);
$results = $query->execute();
foreach ($results as $profile) {
$fields[$profile['name']] = $this->t($profile['title']);
}
return $fields;
}
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'uid' => [
'type' => 'integer',
'alias' => 'pv',
],
];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.