Problem/Motivation
I have Drupal 11.2.4 with https://www.drupal.org/project/email_tfa. In hook_mail(), email_tfa adds the key 'language' => $language to the token options array, where $language is the language-id string. Why this happens is an issue with email_tfa and not a reason for this issue here --- but important to understand the following:
scheduler_content_moderation_integration.tokens.inc hook_tokens() uses this logic to get the $language_code:
$language_code = isset($options['language']) ? $options['language']->language : NULL;
It treats $options['language'] as an object, trying to access $options['language']->language.
In collaboration with email_tfa's hook_mail() this causes the following php-warning:
Warning: Attempt to read property "language" on string in scheduler_content_moderation_integration_tokens() (line 32 of modules/contrib/scheduler_content_moderation_integration/scheduler_content_moderation_integration.tokens.inc).
After some research i found this longer discussion for the scheduler module: https://www.drupal.org/project/scheduler/issues/3144568 and this resulted in following question:
As the scheduler_content_moderation_integration says: "This is a submodule for the scheduler module..." i wonder why it doesn't follow the scheduler's logic to get the $language_code? So it should be $language_code = $options['langcode'] ?? NULL; (shorthand for #14 of the scheduler's issue).
Maybe this was a mistake while merging all patch-contents of this huge issue: https://www.drupal.org/project/scheduler/issues/2798689?
Anyways, the current approach won't work at all, as according to the discussion in https://www.drupal.org/project/scheduler/issues/3144568, it's not common to pass an object into the token options array.
Proposed resolution
Follow scheduler's logic to get $language_code
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
drupatz commentedComment #4
drupatz commentedComment #5
smustgrave commentedIs this only a problem when using this module? May want to add a test case showing this is a generic problem
Comment #6
gogowitsch commentedI am using the module https://www.drupal.org/project/otp (not email_tfa), but have the exact problem described above.
I can confirm that the bug is fixed by merge request !87.
Comment #7
smustgrave commentedActually this is minor enough I'm fine with it.