You are here

function redhen_connection_entity_delete in RedHen CRM 8

Implements hook_entity_delete().

File

modules/redhen_connection/redhen_connection.module, line 148
Contains redhen_connection.module..

Code

function redhen_connection_entity_delete(EntityInterface $entity) {

  // @todo replace with event dispatcher/subscribers.
  // When deleting contacts and orgs, also delete their connections.
  if (in_array($entity
    ->getEntityTypeId(), [
    'redhen_contact',
    'redhen_org',
  ])) {
    $connections = \Drupal::service('redhen_connection.connections')
      ->getConnections($entity, NULL, NULL, FALSE);
    foreach ($connections as $connection) {

      /** @var \Drupal\redhen_connection\ConnectionInterface $connection */
      $connection
        ->delete();
    }
  }
}