This commit is contained in:
naomi 2022-05-18 13:54:06 +01:00
parent 1c61f2f0a4
commit 9351768b25
3 changed files with 13 additions and 22 deletions

View File

@ -68,19 +68,6 @@ function opencase_cases_theme() {
];
}
/**
* @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_oc_case_fee_update(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void {
$case = $case_fee->getCase();
@ -119,13 +106,6 @@ 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();
}
}
/**

View File

@ -92,11 +92,21 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface
}
public function deleteCaseProvisions(): void {
$query = \Drupal::entityQuery('oc_case_provision')
$this->deleteChildren('oc_case_provision');
}
public function deleteActivities(): void {
$this->deleteChildren('oc_activity');
}
public function deleteChildren($child_entity_type):void {
$query = \Drupal::entityQuery($child_entity_type)
->condition('oc_case.target_id', $this->id());
$ids = $query->execute();
foreach($ids as $id) {
OCcaseProvision::load($id)->delete();
\Drupal::entityTypeManager()
->getStorage($child_entity_type)
->load($id)->delete();
}
}

View File

@ -59,6 +59,7 @@ function opencase_oc_case_provision_update(OCCaseProvision $case_provision): voi
function opencase_oc_case_delete(OCCase $case): void {
$case->deleteCaseProvisions();
$case->deleteActivities();
}
/**