Commit 19c4857e authored by Paul Smith's avatar Paul Smith Committed by Pravin Gaikwad
Browse files

Issue #3221673 by MrDaleSmith, Rajeshreeputra: admin/gdpr/tasks page throws an error

parent 64741b81
Loading
Loading
Loading
Loading
+25 −0
Changes for modules/gdpr_tasks/gdpr_tasks.module: 25 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ use Drupal\file\FileInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityDisplayInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\user\UserInterface;

/**
 * Implements hook_theme().
@@ -181,3 +182,27 @@ function gdpr_tasks_entity_view_alter(array &$build, EntityInterface $entity, En
  }

}

/**
 * Implements hook_ENTITY_TYPE_predelete().
 */
function gdpr_tasks_user_predelete(EntityInterface $entity) {
  // @todo Consider options for deleting related data if the user has cancelled
  // their account.
  $storage = \Drupal::entityTypeManager()->getStorage('gdpr_task');
  $query = $storage->getQuery();
  $or = $query->orConditionGroup()
    ->condition('requested_by', $entity->id())
    ->condition('user_id', $entity->id());
  $query->condition($or);

  if ($tasks = $query->execute()) {
    /** @var \Drupal\gdpr_tasks\Entity\TaskInterface $task */
    foreach ($storage->loadMultiple($tasks) as $task) {

      // For now, we can safely assume a deleted user can have their
      // outstanding requests deleted.
      $task->delete();
    }
  }
}