Warning: trying to read property "language" on string

Created on 30 April 2024, about 2 months ago

Problem/Motivation

Hello! I'm using Comment Notify on a Drupal 10.2.5 forum. I've had this warning for a while but only took time to investigate today. Relevant context: the website is set to French only, and I also use the module Email TFA → to force users to login in two steps: 1. normal login form for username and password, then after submit 2. field to enter the verification code sent by email.


First step, all is well.

I don't have time to explore the why right now, but at the top of the second step form, I get this warning from Comment Notify:

Warning: Attempt to read property "language" on string in comment_notify_tokens() (line 38 of modules/contrib/comment_notify/comment_notify.tokens.inc).
comment_notify_tokens('entity', Array, Array, Array, Object)
call_user_func_array(Object, Array) (Line: 409)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'comment_notify') (Line: 388)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('tokens', Object) (Line: 408)
Drupal\Core\Extension\ModuleHandler->invokeAll('tokens', Array) (Line: 364)
Drupal\Core\Utility\Token->generate('entity', Array, Array, Array, Object) (Line: 1094)
token_tokens('user', Array, Array, Array, Object)
call_user_func_array(Object, Array) (Line: 409)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'token') (Line: 388)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('tokens', Object) (Line: 408)
Drupal\Core\Extension\ModuleHandler->invokeAll('tokens', Array) (Line: 364)
Drupal\Core\Utility\Token->generate('user', Array, Array, Array, Object) (Line: 241)
Drupal\Core\Utility\Token->doReplace(1, 'ChĂšre [user:name],
    
Le code de sécurité à usage unique pour finaliser ton authentification à double facteur est : [user:email_tfa]
    
Bien entendu, ne le partage Ă  personne !    

Merci,
La Composi'team', Array, Array, Object) (Line: 191)
Drupal\Core\Utility\Token->replace('ChĂšre [user:name],
    
Le code de sécurité à usage unique pour finaliser ton authentification à double facteur est : [user:email_tfa]
    
Bien entendu, ne le partage Ă  personne !    

Merci,
La Composi'team', Array, Array) (Line: 85)
_email_tfa_mail_text('body', Array, 'fr') (Line: 48)
email_tfa_mail('send_email_tfa', Array, Array)
call_user_func_array(Object, Array) (Line: 400)
Drupal\Core\Extension\ModuleHandler->invoke('email_tfa', 'mail', Array) (Line: 272)
Drupal\Core\Mail\MailManager->doMail('email_tfa', 'send_email_tfa', 'marine.gandy@gmail.com', 'fr', Array, NULL, 1) (Line: 180)
Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 179)
Drupal\Core\Mail\MailManager->mail('email_tfa', 'send_email_tfa', 'marine.gandy@gmail.com', 'fr', Array) (Line: 321)
Drupal\email_tfa\Form\EmailTfaVerifyLoginForm->sendEmail('4', 'GYCyISMcRRKKMoeUmuWJ6slvj7lgSKc7gvT1MSD0ebA') (Line: 171)
Drupal\email_tfa\Form\EmailTfaVerifyLoginForm->buildForm(Array, Object, '4', 'GYCyISMcRRKKMoeUmuWJ6slvj7lgSKc7gvT1MSD0ebA')
call_user_func_array(Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm('email_tfa_email_tfa_verify_login', Object) (Line: 283)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Basically, I see 3 issues here:

    somehow comment_notify_token() is triggered twice when Email TFA sends its verification email, probably because the email text includes 2 tokens, but like I said I don't have time to dig,
    comment_notify_tokens() line 38 incorrectly assumes that $options['language'] is always an object, when in my case it is just a langcode string ('fr')
    the warning is displayed to our users :D

So this issue aims to makes you aware of n°1, and for me to open a merge request to fix n°2 and 3 :) One could argue that solving n°1 would make solving n°2 redundant, but I feel like it's best to remove assumptions from the code if we notice them.

Steps to reproduce

  • Start with a fresh D10 install, with comments enabled and configured on a content type + Comment Notify and Email TFA enabled
  • Basic configuration: see attached screenshots. The node bundle used for Comment Notify doesn't really matter I think. Do make sure in the Email TFA global tab that email body includes tokens, like [user:name] for example (but I use the default text so they should be there already).


    Comment Notify configuration.


    Email TFA configuration.

  • Try to login, the warning should now appear

Proposed resolution

Replace comment_notify.tokens.inc line 38 $language_code = $options['language']->language; with something like $language_code = is_object($options['language']) ? $options['language']->language : $options['language'];

Remaining tasks

Understand why Comment Notify token implementation is triggered by another module's emails, I guess :D

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

1.4

Component

Code

Created by

đŸ‡«đŸ‡·France Mupsi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024