TypeError: Drupal\commerce_email\EmailSender::replaceTokens(): Argument #1 ($value) must be of type string, null given, called in /var/www/drupal10/web/modules/contrib/commerce_email/src/EmailSender.php on line 111 in Drupal\commerce_email\EmailSender->replaceTokens() (line 158 of /var/www/drupal10/web/modules/contrib/commerce_email/src/EmailSender.php).

Steps to reproduce

Not sure, but presumably send an email with a null value returned from $email->getReplyTo().

Proposed resolution

Allow null|string argument, or cast the null to an empty string before calling replaceTokens()?

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

fonant created an issue. See original summary.

fonant’s picture

I've hacked a workaround for line 111 of commerce_email/src/EmailSender.php, which I think will fix the problem:

'reply-to' => $this->replaceTokens(($email->getReplyTo() ?? ''), $replacements),

Maybe we need an update function to add empty ReplyTo strings for older orders?

fonant’s picture

Doh! Of course the other way to fix this is to edit each email definition at /admin/commerce/config/emails and just re-save each one.

chetan 11 made their first commit to this issue’s fork.

chetan 11’s picture

Status: Active » Needs review

Please check the above MR.

vmarchuk made their first commit to this issue’s fork.

vmarchuk’s picture

Yeah, I just reproduced it too. In the getReplyTo() method we need to use the default value and that's it.
MR updated with fixes.

jsacksick’s picture

I think the right fix would be to change the code from:

$params = [
      'id' => 'commerce_email_' . $email->id(),
      'from' => $this->replaceTokens($email->getFrom(), $replacements),
      'cc' => $this->replaceTokens($email->getCc(), $replacements),
      'bcc' => $this->replaceTokens($email->getBcc(), $replacements),
      'reply-to' => $this->replaceTokens($email->getReplyTo(), $replacements),
    ];

to:

    $params = [
      'id' => 'commerce_email_' . $email->id(),
      'from' => $this->replaceTokens($email->getFrom(), $replacements),
      'cc' => $this->replaceTokens($email->getCc(), $replacements),
      'bcc' => $this->replaceTokens($email->getBcc(), $replacements),
    ];
    $reply_to = $email->getReplyTo();
    if (!empty($reply_to) {
      $params['reply-to'] = $reply_to;
    }
vmarchuk’s picture

Version: 8.x-1.2 » 8.x-1.x-dev
Status: Needs review » Fixed

Committed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.