You are here

function simplenews_node_delete in Simplenews 3.x

Same name and namespace in other branches
  1. 8.2 simplenews.module \simplenews_node_delete()
  2. 8 simplenews.module \simplenews_node_delete()
  3. 7.2 simplenews.module \simplenews_node_delete()
  4. 7 simplenews.module \simplenews_node_delete()

Implements hook_ENTITY_TYPE_delete() for node entity.

File

./simplenews.module, line 133
Simplenews node handling, sent email, newsletter block and general hooks.

Code

function simplenews_node_delete($node) {
  if (!simplenews_check_node_types($node
    ->getType())) {
    return;
  }

  // Check if pending emails of this newsletter issue exist and delete them.
  $count = \Drupal::service('simplenews.spool_storage')
    ->deleteMails([
    'entity_id' => $node
      ->id(),
    'entity_type' => 'node',
  ]);
  if ($count) {
    \Drupal::messenger()
      ->addWarning(t('@count pending emails for %title were found and deleted.', [
      '%title' => $node
        ->getTitle(),
      '@count' => $count,
    ]));
    \Drupal::logger('simplenews')
      ->alert('Newsletter %title deleted with @count pending emails..', [
      '%title' => $node
        ->getTitle(),
      '@count' => $count,
    ]);
  }
}