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

  1. Install Drupal 11 with moderation_note module enabled
  2. Create or edit any content type with moderation notes enabled
  3. Add a moderation note to the content
  4. Save the note
  5. 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;
}

Command icon 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

iswariya created an issue. See original summary.

iswariya changed the visibility of the branch 3576118-notemail-plugin-breaks to hidden.

iswariya changed the visibility of the branch 3576118-notemail-plugin-breaks to active.

iswariya’s picture

Status: Active » Closed (outdated)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.