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.

1 Answer 1


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!

  • 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?
    – chaydru
    Nov 18, 2021 at 11:52
  • also I get to see "Error: Class 'Drupal\views\Plugin\views\field\BulkForm\CommentBulkForm' not found in include()" error from the plugin. :(
    – chaydru
    Nov 18, 2021 at 12:03
  • nm, this worked like a charm!! thanks a lot!
    – chaydru
    Nov 18, 2021 at 14:06
  • 1
    This message is used (and shared) by the various actions available via the CommentBulkForm ViewsField plugin. Dec 8, 2021 at 21:50
  • 1
    That would need a separate question I believe. Dec 9, 2021 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.