Last active
June 26, 2017 16:57
-
-
Save adityaanurag/481412d0e730e9dccb8d696b2f635940 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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