CRM_Utils_Hook::pre('delete', $entityName, $record['id'], $record);
$instance = new $className();
$instance->id = $record['id'];
- if (!$instance->delete()) {
+ // Load complete object for the sake of hook_civicrm_post, below
+ $instance->find(TRUE);
+ if (!$instance || !$instance->delete()) {
throw new CRM_Core_Exception("Could not delete {$entityName} id {$record['id']}");
}
+ // For other operations this hook is passed an incomplete object and hook listeners can load if needed.
+ // But that's not possible with delete because it's gone from the database by the time this hook is called.
+ // So in this case the object has been pre-loaded so hook listeners have access to the complete record.
CRM_Utils_Hook::post('delete', $entityName, $record['id'], $instance);
return $instance;