You are here

function node_authlink_batch_delete in Node authorize link 8

Same name and namespace in other branches
  1. 7 node_authlink.module \node_authlink_batch_delete()

Delete authkeys for all nodes in node type.

Parameters

array $form: Form.

\Drupal\Core\Form\FormStateInterface $form_state: Form state.

1 string reference to 'node_authlink_batch_delete'
node_authlink_form_node_type_form_alter in ./node_authlink.module
Alter of node_type_form.

File

./node_authlink.module, line 167
Node Authlink hooks and alters.

Code

function node_authlink_batch_delete(array &$form, FormStateInterface &$form_state) {

  // NIDs of nodes that are in this node type.
  $query = \Drupal::database()
    ->select('node', 'n');
  $query
    ->leftJoin('node_authlink_nodes', 'a', 'n.nid = a.nid');
  $query
    ->fields('n', [
    'nid',
  ])
    ->condition('type', $form_state
    ->getValue('type'))
    ->isNotNull('authkey');
  $nids = $query
    ->execute()
    ->fetchCol();
  foreach ($nids as $nid) {
    node_authlink_delete($nid);
  }
  \Drupal::messenger()
    ->addMessage(t('%num authkeys has been deleted.', [
    '%num' => count($nids),
  ]));
}