Error sending email, subscribe button is not displayed correctly

Created on 22 February 2023, over 1 year ago
Updated 3 March 2023, over 1 year ago

Problem/Motivation

Error in queue

TypeError: forum_notifications_subscription_email_queue(): Argument #4 ($user_id) must be of type string, null given, called in /code/web/modules/contrib/forum_notifications_subscription/forum_notifications_subscription.module on line 373 in forum_notifications_subscription_email_queue() (line 406 of /code/web/modules/contrib/forum_notifications_subscription/forum_notifications_subscription.module)

Additionally, the subscription button is not displayed correctly in the forums

Steps to reproduce

Subscribe to the notifications and send the emails with the Cron

Proposed resolution

In forum_notifications_subscription.module, line 373, a NULL value is sending

if ($frequency->getFrequency() == 'Daily Digest Emails') {
              forum_notifications_subscription_email_queue($email, $params['title'], $params['message'], $subscriberUser->id(), 'Daily Digest Emails');
            }
            elseif ($frequency->getFrequency() == 'Single Emails') {
              \Drupal::logger('forum_notifications_subscription')
                ->notice($settings['cron'] . " Cron value");
              if ($settings['cron']) {
                forum_notifications_subscription_email_queue($email, $params['title'], $params['message'], NULL, 'Single Emails');
              }
              else {
                forum_notifications_subscription_emailer('forum_notifications_subscription', 'single_email_queue', $email, $params['title'], $params['message']);
              }
            }

And this value is received by this function in line 406, this function need a string value.

function forum_notifications_subscription_email_queue(string $to, string $subject, string $message, string $user_id, string $queue_type) {
  $data['to'] = $to;
  $data['title'] = $subject;
  $data['message'] = $message;

  $queue_factory = \Drupal::service('queue');
  if ($queue_type == 'Daily Digest Emails') {
    $data['user_id'] = $user_id;
    $queue = $queue_factory->get('daily_digest_email_queue');
    $queue->createQueue();
    $queue->createItem($data);
  }
  elseif ($queue_type == 'Single Emails') {
    $queue = $queue_factory->get('single_email_queue');
    $queue->createQueue();
    $queue->createItem($data);
  }
}

My "easy solution" is change the NULL value for a number 0, Line 373

if ($settings['cron']) {
                forum_notifications_subscription_email_queue($email, $params['title'], $params['message'],0, 'Single Emails');
              }

Also i delete the #type line in the fields of the form to get a properly display in forum_notifications_subscription.module

Lines 103 to 110

$build['forum_notifications_subscription'] = [
        '#type' => 'fieldset',
        '#prefix' => "<div class='forum-topic-subscription-options'>",
        '#suffix' => '</div>',
        '#cache' => [
          'tags' => ['forum_notification_frequency_list'],
        ],
      ];

Lines 128 to 136

$build['forum_notifications_subscription'] = [
        '#type' => 'fieldset',
        '#prefix' => "<div class='forum-main-subscription-options'>",
        //        '#prefix' => "<div>" . $description,
        '#suffix' => '</div>',
        '#cache' => [
          'tags' => ['forum_notification_frequency_list'],
        ],
      ];

You can do the respective tests

πŸ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jeffersonpatron

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΈπŸ‡³Senegal diaodiallo

    Hi jeffersonpatron, thanks for your good help here.

    I think it's a good solution for the PHP issue. Can you please give more clarification about the #type attributes?
    To go quickly with the urgent PHP patch we should maybe take off the UI issue before we have more understanding and unanimity.

    Manu thanks

Production build 0.71.5 2024