Warning due to string passed to foreach

Created on 9 October 2023, about 1 year ago
Updated 6 February 2024, 11 months ago

Problem/Motivation

Thanks for the excellent module!

I'm getting lots of warnings like this in my logs:

<em class="placeholder">Warning</em>: foreach() argument must be of type array|object, string given in <em class="placeholder">Drupal\hubspot\Plugin\WebformHandler\HubspotWebformHandler-&gt;remotePost()</em> (line <em class="placeholder">750</em> of <em class="placeholder">modules/contrib/hubspot/src/Plugin/WebformHandler/HubspotWebformHandler.php</em>).

Line 749 and 750 are:

if (isset($settings['subscriptions'])) {
      foreach ($settings['subscriptions'] as $subscription) {

I've saved by Hubspot Webform handler with no subscriptions added. The result is that $settings['subscriptions'] ends up being an empty string.

Steps to reproduce

Submit a form with a Hubspot Webform handler added that has no subscriptions configured.

Proposed resolution

Add a couple code checks to the handler to ensure that $settings['subscriptions'] is an array while also handling an empty string gracefully. For one, change the isset in line 749 to a !empty.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: duplicate

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

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

Comments & Activities

Production build 0.71.5 2024