Plugin not found

in flag

I am overwriting the CommentBulkForm class in my module.

namespace Drupal\mymod\Plugin\views\field;

use Drupal\comment\Plugin\views\field\CommentBulkForm;

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

   * {@inheritdoc}
  protected function emptySelectedMessage() {
    return $this->t('some other message.');


This file is placed inside mymodule\src\Plugin\views\field. I overwrote the views.view.comment to look for this class. However, I get the following error when I try to load the comments view.

Drupal\Component\Plugin\Exception\PluginException: Plugin (custom_comment_bulk_form) instance class "Drupal\mymod\Plugin\views\field\custom_comment_bulk_form" does not exist. in Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass() (line 97 of /vagrant/web/core/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php).

What's wrong in the code?

cn flag
Could you clean up the module names in the question a bit, just to confirm the problem isn't a typo? You have three listed: ahrq in the code, mymodule in the example path, and mymod in the error message. If you could also confirm that you've cleared cache, the module is enabled, and you've restarted the web server (to flush APCu which can sometimes get in the way), that would be helpful too. Thanks!
in flag
thanks for pointing that typo. I fixed it and did everything you mentioned. still same error :(
ch flag
  1. For PSR-2 loading to work is important:
  • Check namespace, folders are coherent. If your module is ahrq, ensure the namespace uses ahrq, and the folder it sits is ahrq/src/Plugin/views/field. Check the casing is respected just in case (lowercase/uppercase matters).

  • Ensure the file is named CustomCommentBulkForm.php

  1. Yeah, obvious, but have you cleared your cache?
in flag
it was drush cr :) worked lol
gb flag

Plugin (xxx) instance class "Drupal\mymod\Plugin\views\field\custom_comment_bulk_form" does not exist. in Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass()

This happens when you've references to that plugin and Drupal cannot find it.

First step is obviously to try to clear the caches (drush cr, in case of Redis - redis-cli flushall). Alternatively try truncating cache_discovery table where this reference is stored.

If the clear cache didn't work, others things that can be done:

  • Identify and ensure the module using that plugin/namespace is enabled.
  • Ensure class/plugin is defined in module's .services.yml file.
  • Ensure no files are missing, no typos and permission are fine.
  • Re-run composer install.
  • Briefly check Composer's autoload values (such as vendor/composer/autoload* and vendor/composer/installed.json), whether it has the right paths (sometimes mixing different environments or copying/committing these files can mess up with the paths).
  • If this happened after module upgrade: review existing release changes, bugs and patches that you're using. Sometimes the old patch could break the working module on the upgrade.
  • Review code for any typos.
  • Otherwise consider removing/disabling broken code (all the references), then clearing up caches (cache_discovery table), if it's not needed.

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.