Activities get deleted when case deleted.
This commit is contained in:
parent
b194367eef
commit
240a55f54f
@ -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.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user