You are here

function simplenews_node_access in Simplenews 7

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

Implements hook_node_access().

Don't allow deletion when a newsletter is pending

File

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

Code

function simplenews_node_access($node, $op, $account) {
  if ($op == 'delete') {

    // Check if a newsletter is pending
    $query = db_select('simplenews_newsletter', 'n');
    $query
      ->fields('n', array(
      'status',
    ));
    $query
      ->condition('n.nid', $node->nid);
    $result = $query
      ->execute();
    if ($result
      ->rowCount()) {
      $status = $result
        ->fetch();
      if ($status->status == SIMPLENEWS_STATUS_SEND_PENDING) {
        drupal_set_message(t('You can\'t delete this newsletter because it has not been sent to all its subscribers.'), 'warning');
        return NODE_ACCESS_DENY;
      }
    }
  }
  return NODE_ACCESS_IGNORE;
}