You are here

function simplenews_node_delete in Simplenews 8

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

Implements hook_node_delete().

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 these too.
  $count = \Drupal::service('simplenews.spool_storage')
    ->deleteMails(array(
    'entity_id' => $node
      ->id(),
    'entity_type' => 'node',
  ));
  if ($count) {
    \Drupal::messenger()
      ->addWarning(t('@count pending emails for %title were found and deleted.', array(
      '%title' => $node
        ->getTitle(),
      '@count' => $count,
    )));
    \Drupal::logger('simplenews')
      ->alert('Newsletter %title deleted with @count pending emails..', array(
      '%title' => $node
        ->getTitle(),
      '@count' => $count,
    ));
  }
}