Skip to content

Instantly share code, notes, and snippets.

@rpayanm
Created January 8, 2020 13:46
Show Gist options
  • Save rpayanm/ca97458d2141b5dc27fb542f549ffbad to your computer and use it in GitHub Desktop.
Save rpayanm/ca97458d2141b5dc27fb542f549ffbad to your computer and use it in GitHub Desktop.
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment