Problem/Motivation

The doc block for pet_send_one_mail() indicates that the only parameters required in the $params array are 'pet_from' and 'pet_to' and makes no mention of a 'language' parameter. However, line 266 assumes that $params['language'] is an object. If $params['language'] is not defined or is not an object, the function fails with "Call to a member function getId() on null".

Steps to reproduce

Attempt to use pet_send_one_mail() without defining $params['language'].

Proposed resolution

Check whether $params['language'] is defined, and if not, use \Drupal::languageManager()->getCurrentLanguage() instead.

Add to the doc block for the function to indicate that 'language' is an optional parameter.

Remaining tasks

Make a fork.

Issue fork pet-3407135

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

BenStallings created an issue. See original summary.

benstallings’s picture

Status: Active » Needs review

While I was at it, I also provided an empty string to satisfy the trim() function in case $pet->getMailbodyPlain() returns null.

  • Sharique committed 8c747d10 on 8.x-4.x
    Issue #3407135 by BenStallings: Language is not a required parameter
    
sharique’s picture

Status: Needs review » Fixed

Thanks BenStallings, good find.

Status: Fixed » Closed (fixed)

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

cwales95’s picture

Hi, this issue doesn't seem to be fixed.

The issue persists because the code in pet_substitutions expects $params['language'] to be set but $params['language'] is set directly after pet_substitutions is called.

Can we reopen this issue?

sharique’s picture

@cwales95, yes, you can. Please test with latest code in branch as well.
I'll appreciate if you can post a patch as well.
Unfortunately, I don't have enough time to look into issues.

benstallings’s picture

@Sharique I've updated the branch, but I am unable to reopen the issue. It says "Only maintainers can reopen."

benstallings’s picture

@sharique yes, and I had already done so at https://git.drupalcode.org/project/pet/-/merge_requests/5/diffs?diff_id=... , but for some reason https://git.drupalcode.org/project/pet/-/merge_requests/5/diffs shows an incorrect "latest version" until you select "latest version" again.