Commit cda53994 authored by baldwinlouie's avatar baldwinlouie Committed by Yas Naoi
Browse files

Issue #3325053 by baldwinlouie, yas: Refactor to reassign UID for Terraform entities

parent 6da68ff8
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -77,6 +77,32 @@ function terraform_cloud_config_delete(CloudConfig $cloud_config): void {
  }
}

/**
 * Implements hook_ENTITY_TYPE_predelete().
 */
function terraform_user_predelete($account): void {
  /** @var Drupal\cloud\Service\CloudService $cloud_service */
  $cloud_service = \Drupal::service('cloud');
  $entity_types = $cloud_service->getProviderEntityTypes('terraform');
  foreach ($entity_types ?: [] as $entity_type) {
    if (empty($entity_type)) {
      continue;
    }
    $ids = \Drupal::entityTypeManager()
      ->getStorage($entity_type->id())
      ->getQuery()
      ->accessCheck(TRUE)
      ->condition('uid', $account->id())
      ->execute();
    if (count($ids) === 0) {
      continue;
    }
    $cloud_service->reassignUids($ids, [
      'uid' => 0,
    ], $entity_type->id(), FALSE, $account);
  }
}

/**
 * Get fieldsets of cloud config page.
 *