'#ajax' => ['callback'
is weird.
Looking at examples from Drupal core, there seems to be a bunch of different ways you can call it...
-
'callback' => 'some_global_function'
is the simplest and always seems to work, but the function it calls has to be defined in a.module
file, not a class. -
'callback' => [$this, 'someFunction']
works sometimes, but you get a 'cannot serialize database service' error if any of$this
' properties (or anything they reference) involves a database connection. -
'callback' => [static::class, 'someFunction']
works, but callssomeFunction()
in a static context, meaning you can't use$this->someService->doSomething()
.This is equivalent to, and has the same problems as:
-
'callback' => [get_class($this), 'someFunction']
,