Activities get deleted when case deleted.

This commit is contained in:
naomi 2021-12-30 13:43:19 +00:00
parent b194367eef
commit 240a55f54f

View File

@ -79,6 +79,20 @@ function opencase_cases_get_case_fees(Drupal\opencase_cases\entity\OCCase $case)
return $case_fees;
}
/**
* @return Drupal\opencase_cases\entity\OCActivity[]
*/
function opencase_cases_get_activities(Drupal\opencase_cases\entity\OCCase $case): array {
$query = \Drupal::entityQuery('oc_activity')
->condition('oc_case.target_id', $case->id());
$activity_ids = $query->execute();
$activities = [];
foreach($activity_ids as $id) {
$activities[] = Drupal\opencase_entities\Entity\OCActivity::load($id);
}
return $activities;
}
function opencase_cases_get_amount(Drupal\opencase_cases\entity\OCCaseFee $case_fee): string {
return $case_fee->amount->first()->value;
}
@ -132,6 +146,15 @@ function opencase_cases_entity_base_field_info($entity_type) {
return $fields;
}
// When deleting a case, delete the activities associated with it
function opencase_cases_oc_case_delete(Drupal\opencase_cases\Entity\OCCase $case): void {
$activities = opencase_cases_get_activities($case);
foreach ($activities as $activity) {
$activity->delete();
}
}
/**
* When creating an activity, it sets the case id from the URL.
*/