node_mass_update example


function hook_user_cancel($edit, UserInterface $account$method) {
  switch ($method) {
    case 'user_cancel_block_unpublish':
      // Unpublish nodes (current revisions).       \Drupal::moduleHandler()->loadInclude('node', 'inc', 'node.admin');
      $nodes = \Drupal::entityQuery('node')
        ->accessCheck(FALSE)
        ->condition('uid', $account->id())
        ->execute();
      node_mass_update($nodes['status' => 0], NULL, TRUE);
      break;

    case 'user_cancel_reassign':
      // Anonymize nodes (current revisions).       \Drupal::moduleHandler()->loadInclude('node', 'inc', 'node.admin');
      $nodes = \Drupal::entityQuery('node')
        ->accessCheck(FALSE)
        ->condition('uid', $account->id())
        ->execute();
      node_mass_update($nodes['uid' => 0], NULL, TRUE);
      // Anonymize old revisions.
Home | Imprint | This part of the site doesn't use cookies.