Skip to content

Instantly share code, notes, and snippets.

@adityaanurag
Last active June 26, 2017 16:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adityaanurag/481412d0e730e9dccb8d696b2f635940 to your computer and use it in GitHub Desktop.
Save adityaanurag/481412d0e730e9dccb8d696b2f635940 to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\batch_example;
use Drupal\node\Entity\Node;
class DeleteNode {
public static function deleteNodeExample($nids, &$context){
$message = 'Deleting Node...';
$results = array();
foreach ($nids as $nid) {
$node = Node::load($nid);
$results[] = $node->delete();
}
$context['message'] = $message;
$context['results'] = $results;
}
function deleteNodeExampleFinishedCallback($success, $results, $operations) {
// The 'success' parameter means no fatal PHP errors were detected. All
// other error management should be handled using 'results'.
if ($success) {
$message = \Drupal::translation()->formatPlural(
count($results),
'One post processed.', '@count posts processed.'
);
}
else {
$message = t('Finished with an error.');
}
drupal_set_message($message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment