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
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 #3
benstallings commentedWhile I was at it, I also provided an empty string to satisfy the trim() function in case $pet->getMailbodyPlain() returns null.
Comment #5
sharique commentedThanks BenStallings, good find.
Comment #7
cwales95 commentedHi, this issue doesn't seem to be fixed.
The issue persists because the code in
pet_substitutionsexpects$params['language']to be set but$params['language']is set directly afterpet_substitutionsis called.Can we reopen this issue?
Comment #8
sharique commented@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.
Comment #9
benstallings commented@Sharique I've updated the branch, but I am unable to reopen the issue. It says "Only maintainers can reopen."
Comment #10
benstallings commented@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.