rpayanm
1/8/2020 - 1:46 PM

Ajax callback doesn't work with Dependency Injector

private $service;

public function __construct($service) {
  $this->service = $service;
}

Call to a member function ...() on null in Drupal\...\Form\...->buildForm()

The problem is is your use of private. Don't use it, use protected. Drupal has a special logic to prevent services from being serialized but it doesn't work properly on private properties, as they are invisible to the trait that is used for that.