Overwrite a specific VBO action processed message

in flag

I am using VBO to perform bulk operations on my view. I have 2 core VBO actions and 2 custom actions.

  • Publish comment
  • Unpublish comment
  • Publish resource
  • Unpublish resource

When the Apply action button is clicked with none of the grid row is selected, I get this error message.

Select one or more comments to perform the update on.

I would like to rewrite this error message as An attachment has to be selected to perform this action.

How can I achieve this? I am aware of hook_views_bulk_operations_finish(), but it doesn't overwrite a specific action.

in flag

You could try the following:

  1. Define your own ViewsField plugin that extends the CommentBulkForm (that is where that message comes from)

namespace Drupal\your_module\Plugin\views\field;

use Drupal\views\Plugin\views\field\BulkForm;

 * Defines a custom comment operations bulk form element.
 * @ViewsField("custom_comment_bulk_form")
class CustomCommentBulkForm extends CommentBulkForm {

   * {@inheritdoc}
  protected function emptySelectedMessage() {
    return $this->t('An attachment has to be selected to perform  this action.');


  1. Expose your plugin to views:
function your_module_views_data() {

  $data['comment']['custom_comment_bulk_form'] = [
    'title' => t('Custom comment operations bulk form'),
    'help' => t('Add a form element that lets you run operations on multiple comments, with custom messages.'),
    'field' => [
      'id' => 'custom_comment_bulk_form',

  return $data;
  1. Finally, overwrite (or override) your (views.view.) Comments configuration so that your existing 'Comment: Comment operations bulk form' field is forced to use your ViewsField plugin. One way to overwrite would be via drush:
drush cset views.view.comment \
  display.default.display_options.fields.comment_bulk_form.field \

That would eventually allow you to set your own custom message:

enter image description here

Good luck!

in flag
Got a question. I have created the ViewsField plugin inside my module at this path - mymodule\src]plugin\views\field\custom_comment_bulk_form.php. But this path is nowhere referenced, neither in hook_views_data() nor in the config file. So how will my custom plugin file be read?
in flag
also I get to see "Error: Class 'Drupal\views\Plugin\views\field\BulkForm\CommentBulkForm' not found in include()" error from the plugin. :(
in flag
nm, this worked like a charm!! thanks a lot!

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.