function apigee_edge_developer_storage_load in Apigee Edge 8
Implements hook_ENTITY_TYPE_storage_load().
Set Drupal owner ids on developers after they were loaded from Apigee Edge.
File
- ./
apigee_edge.module, line 1613 - Copyright 2018 Google Inc.
Code
function apigee_edge_developer_storage_load(array $entities) {
$developerId_mail_map = [];
/** @var \Drupal\apigee_edge\Entity\Developer $entity */
foreach ($entities as $entity) {
$developerId_mail_map[$entity
->getDeveloperId()] = $entity
->getEmail();
}
$query = \Drupal::database()
->select('users_field_data', 'ufd');
$query
->fields('ufd', [
'mail',
'uid',
])
->condition('mail', $developerId_mail_map, 'IN');
$mail_uid_map = $query
->execute()
->fetchAllKeyed();
foreach ($entities as $entity) {
// If developer id is not in this map it means the developer does not exist
// in Drupal yet (developer syncing between Apigee Edge and Drupal is
// required) or the developer id has not been stored in related Drupal user
// yet. This can be fixed with running developer sync too, because it could
// happen that the user had been created in Drupal before Apigee Edge
// connected was configured. Although, this could be a result of a previous
// error but there should be a log about that.
if (isset($mail_uid_map[$developerId_mail_map[$entity
->getDeveloperId()]])) {
$entity
->setOwnerId($mail_uid_map[$developerId_mail_map[$entity
->getDeveloperId()]]);
}
}
}