Problem/Motivation
After upgrading to Drupal 11, saving moderation notes fails with the following error:
Warning: Attempt to read property "server" on null in Drupal\Core\Mail\Plugin\Mail\PhpMail->mail() (line 115)
Error: Call to a member function has() on null in Drupal\Core\Mail\Plugin\Mail\PhpMail->mail() (line 115)
In Drupal 11, the PhpMail class constructor now initializes $this->request = \Drupal::request() which is required by the mail() method. The NoteMail class in this module extends PhpMail and overrides the constructor, but does not call parent::__construct(), leaving $this->request as null.
When parent::mail($message) is called, it tries to access $this->request->server->has('WINDIR') which fails because $this->request was never initialized.
Steps to reproduce
- Install Drupal 11 with moderation_note module enabled
- Create or edit any content type with moderation notes enabled
- Add a moderation note to the content
- Save the note
- Error occurs when the module attempts to send email notification
Proposed resolution
Add parent::__construct() call in NoteMail::__construct() to ensure the parent class properly initializes the request object:
public function __construct(StateInterface $state, ConfigFactoryInterface $config_factory) {
parent::__construct();
$this->state = $state;
$this->configFactory = $config_factory;
}
Issue fork moderation_note-3576118
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
iswariya commented