Skip to content

Instantly share code, notes, and snippets.

@rpayanm
Created January 8, 2020 13:46
Show Gist options
  • Select an option

  • Save rpayanm/ca97458d2141b5dc27fb542f549ffbad to your computer and use it in GitHub Desktop.

Select an option

Save rpayanm/ca97458d2141b5dc27fb542f549ffbad to your computer and use it in GitHub Desktop.

Revisions

  1. rpayanm created this gist Jan 8, 2020.
    12 changes: 12 additions & 0 deletions ajax-callback-di.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    ```
    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.