Warning: Invalid argument supplied for foreach() in Drupal\campaignmonitor\CampaignMonitorSubscriptionManager->userSubscribe() (line 438 of modules/contrib/campaignmonitor/src/CampaignMonitorSubscriptionManager.php).

Created on 11 August 2021, over 3 years ago
Updated 28 April 2023, over 1 year ago

Problem/Motivation

When an anonymous user signs up and there's no name field in the form, it throws this error:
Warning: Invalid argument supplied for foreach() in Drupal\campaignmonitor\CampaignMonitorSubscriptionManager->userSubscribe() (line 438 of modules/contrib/campaignmonitor/src/CampaignMonitorSubscriptionManager.php).

Also, as we are given the option to select a different first/last name fields, we should want to use that instead of the default Drupal core name field, so let's use the core name field as a backup if there's not another field configured for it.

Steps to reproduce

  • Create a form without a name field.
  • Test as anonymous user.
  • Put an debug breakpoint at line 419 of CampaignSubscriptionManager.php

Proposed resolution

Get the $settings before the if statement and evaluate if the name setting is set to show (true) or not.
If it's not true, get the name from the configured fields.
If there are no configured fields for the name or if it's empty, then set $name to $email.

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Chris Dart

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.

  • πŸ‡¦πŸ‡ΊAustralia VladimirAus Brisbane, Australia

    Not sure what is the point of this if

    -            foreach ($merge_vars as $key => $var) {
    -              if ($field == $key) {
    -                $name[] = $var;
    +            if (!empty($merge_vars)) {
    +              foreach ($merge_vars as $key => $var) {
    +                if ($field == $key) {
    +                  $name[] = $var;
    +                }
    

    Loop won't go through on empty $merge_vars anyway.

Production build 0.71.5 2024