class UsersMapping in Replication 8.2
Same name and namespace in other branches
- 8 src/UsersMapping.php \Drupal\replication\UsersMapping
Hierarchy
- class \Drupal\replication\UsersMapping
Expanded class hierarchy of UsersMapping
2 files declare their use of UsersMapping
- ContentEntityNormalizer.php in src/
Normalizer/ ContentEntityNormalizer.php - FileEntityNormalizer.php in src/
Normalizer/ FileEntityNormalizer.php
1 string reference to 'UsersMapping'
1 service uses UsersMapping
File
- src/
UsersMapping.php, line 9
Namespace
Drupal\replicationView source
class UsersMapping {
/**
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager) {
$this->configFactory = $config_factory;
$this->entityTypeManager = $entity_type_manager;
}
/**
* Returns UID from replication.settings config object.
*
* @return int
*/
public function getUidFromConfig() {
return $this->configFactory
->get('replication.settings')
->get('uid');
}
/**
* Maps user reference field.
*
* @param array $entity
* @param string $field_name
*
* @return array
*/
public function mapReferenceField($entity, $field_name) {
$field_info = [];
foreach ($entity[$field_name] as $delta => $item) {
$users = [];
if (isset($item['username'])) {
$users = $this->entityTypeManager
->getStorage('user')
->loadByProperties([
'name' => $item['username'],
]);
}
$user = reset($users);
if ($user instanceof UserInterface && ($id = $user
->id())) {
$field_info[$delta] = [
'target_id' => $id,
];
}
else {
$field_info[$delta] = [
'target_id' => $this
->getUidFromConfig(),
];
}
}
return $field_info;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UsersMapping:: |
protected | property | ||
UsersMapping:: |
protected | property | ||
UsersMapping:: |
public | function | Returns UID from replication.settings config object. | |
UsersMapping:: |
public | function | Maps user reference field. | |
UsersMapping:: |
function |