I have a view based on view bulk operations. this is a comment based view and performs the below actions:
1. Publish comment 2. Unpublish comment
When one of these actions are selected to be executed on a set of records, I get to see a success message like below:
Action processing results: Unpublish Comment (1).
I would like to alter the success message as:
The selected comment(s) have been unpublished successfully
I am using VBO 4.0.0 which has action processing message update commit in it. No clue about how this can be implemented for a specific actions. any help?
UPDATE:
Below is my trial so far:
function mymod_batch_alter(&$batch) {
foreach ($batch['sets'] as $key => $set) {
$batch['sets'][$key]['finished'] = 'mymod_views_bulk_operations_execute_finished';
}
}
/**
* Implements hook_views_bulk_operations_execute_finish().
*/
function mymod_views_bulk_operations_execute_finished($success, array $results, array $operations) {
if ($success) {
$operations = $results['operations'];
if($operations == "Approve Comment"){
$message = \Drupal::messenger()->addMessage('Success! Approved');
}
elseif($operations == "Disapprove Comment"){
$message = \Drupal::messenger()->addMessage('Success! Disapproved');
}
}
else {
$message = \Drupal::messenger()->addWarning('Failure message...');
}
return NULL;
}
This code is working well, but just one issue. everytime, even for the "disapprove comment" action, I get to see "Success! Approved" message. Control is going into wrong if-condition. Can someone point the mistake out?