Sometimes there are cryptic error messages in Drupal, and it's hard to understand what exactly is wrong. I had an issue with custom access in one of the routes throwing BadMethodCallException
.
Drupal was complaining about not being able to call my access callback.
BadMethodCallException: The "\Drupal\my_module\Controller\MyController::checkAccess" method is not callable as a _custom_access callback in route "/my_route" in Drupal\Core\Access\CustomAccessCheck->access()
So to solve this, I triple-checked all the namespaces, the file paths and copied all the names to rule out any typos, but nothing helped. After messing around, I decided to check what exactly was failing. I found that one of the services in my controller create()
method was misspelled. After fixing that, the problem was gone.
Hopefully it helps.