You are here

function simplenews_node_access in Simplenews 8

Same name and namespace in other branches
  1. 8.2 simplenews.module \simplenews_node_access()
  2. 7.2 simplenews.module \simplenews_node_access()
  3. 7 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 1081
Simplenews node handling, sent email, newsletter block and general hooks

Code

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

    // Check if a newsletter is pending
    if ($node
      ->hasField('simplenews_issue') && $node->simplenews_issue->status == SIMPLENEWS_STATUS_SEND_PENDING) {
      return AccessResult::forbidden()
        ->addCacheableDependency($node);
    }
  }
}