1

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?

2
  • 1
    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!
    – Clive
    Nov 18, 2021 at 13:30
  • thanks for pointing that typo. I fixed it and did everything you mentioned. still same error :(
    – chaydru
    Nov 18, 2021 at 13:33

2 Answers 2

3
  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?
1
  • 2
    it was drush cr :) worked lol
    – chaydru
    Nov 18, 2021 at 14:06
0

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.

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.