0

I'm trying to override the User entity list_builder handler to add another column to the table and implement some JavaScript search functionality.

The code I'm using is below which is in my modules mm.module file.

function mm_user_override_entity_type_alter(array &$entity_types) {
  $entity_types['user']->setHandlerClass('list_builder', 'Drupal\mm_user_list_builder\UserListBuilder');
}

The issue I'm having is this code gives me the following error

Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException</em>: The &quot;user&quot; entity type did not specify a list_builder handler. 

Which from what I can tell is not correct, even $entity_types['user']->getHandlerClasses() tells me the list_builder handler exists.

Why is this error happening & how best to resolve it? Or is there a better way for me to add a column & search to the user list page?

2
  • Nothing wrong with the approach. Might be a small error, like for example the module name in hook and fully-qualified class name are not the same, in case this is not intentionally.
    – 4uk4
    Aug 21, 2019 at 11:52
  • Thanks @4k4 , it's good to know I'm on the right lines but still cannot see what's causing the problem. Might see if the examples module has anything I could look at.
    – Neil Nand
    Sep 3, 2019 at 13:37

1 Answer 1

1

my_module.module :

<?php

use Drupal\my_module\MyModuleListBuilder;

function my_module_entity_type_alter(array &$entity_types) {
  $entity_types['user']->setHandlerClass('list_builder', MyModuleListBuilder::class);
// $entity_types['user']->setListBuilderClass(MyModuleListBuilder::class); // Other solution possible
}

my_module\src\MyModuleUserListBuilder.php :

<?php

namespace Drupal\my_module;

use Drupal\user\UserListBuilder;

class MyModuleListBuilder extends UserListBuilder {
    // Implement the function you want to edit
}

Your Answer

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

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