简体   繁体   English

Drupal 8.7.8 上的 Webform Mail Chimp 问题

[英]Problem with Webform Mail Chimp on Drupal 8.7.8

Recently we updated a website made with Drupal 8. The update was from core 8.6 to 8.7.8, at the same time all the modules were updated as well.最近我们更新了一个使用 Drupal 8 制作的网站。更新是从核心 8.6 到 8.7.8,同时更新了所有模块。 Among those modules were Webform and Webform Mailchimp .这些模块包括WebformWebform Mailchimp

After that, some of the forms started showing a warning after the form is submitted.之后,部分 forms 在提交表单后开始显示警告。 The e-mail is sent and the data of the form is saved.发送电子邮件并保存表单数据。

strlen() expects parameter 1 to be string, array is given in Drupal\webform_mailchimp\Plugins\WebformHancler\WebformMailChimpHandler->postSave()

The full error details can be seen here: https://prnt.sc/pn76pv完整的错误细节可以在这里看到: https://prnt.sc/pn76pv

I'm new to Drupal so I think I should not go in the source file and make changes myself.我是 Drupal 的新手,所以我认为我不应该在源文件中使用 go 并自己进行更改。 How can I fix this?我怎样才能解决这个问题?

From the error message, we can see that strlen() receives an array instead of a string:从错误消息中,我们可以看到strlen()接收的是数组而不是字符串:

strlen() expects parameter 1 to be string, array is given in [...] WebformMailChimpHandler->postSave() ( line 320 of [...]) strlen() 期望参数 1 是字符串,数组在 [...] WebformMailChimpHandler->postSave() 中给出([...] 的第 320 行

At Line 320 of this module, we have a call to mailchimp_subscribe() :在这个模块的第 320 行,我们调用了mailchimp_subscribe()

mailchimp_subscribe($configuration['list'], $email, array_filter($mergevars, 'strlen'), $configuration['interest_groups'], $double_optin);

The error is caused by what is passed in as the third argument: array_filter($mergevars, 'strlen') , meaning $mergevars - that is expected to be an array of strings to be filtered by strlen - contains an array instead of a string at some point.该错误是由作为第三个参数传入的内容引起的: array_filter($mergevars, 'strlen') ,意思是$mergevars - 应该是一个由strlen过滤的字符串数组 - 包含一个数组而不是字符串在某一点。

How to fix $mergevars ?如何修复$mergevars

We can see it's loaded from a config, and then altered by modules that implement some alter hooks:我们可以看到它是从配置中加载的,然后由实现了一些更改钩子的模块进行更改:

$mergevars = Yaml::decode($configuration['mergevars']);

// Allow other modules to alter the merge vars.
// @see hook_mailchimp_lists_mergevars_alter().
$entity_type = 'webform_submission';
\Drupal::moduleHandler()->alter('mailchimp_lists_mergevars', $mergevars, $webform_submission, $entity_type);
\Drupal::moduleHandler()->alter('webform_mailchimp_lists_mergevars', $mergevars, $webform_submission, $this);

First, you may want to check if $configuration['mergevars'] is correctly set.首先,您可能需要检查$configuration['mergevars']是否设置正确。

Then, you can see what is happening and eventually fix $mergevars in your own hook_alter:然后,您可以看到正在发生的事情并最终在您自己的 hook_alter 中修复$mergevars mergevars:

function MODULE_mailchimp_lists_mergevars_alter(&$mergevars, &$webform_submission, &$entity_type) {
  # debug/fix $mergevars
}

function MODULE_webform_mailchimp_lists_mergevars_alter(&$mergevars, &$webform_submission, &$WebformMailChimpHandler) {
  # debug/fix $mergevars
}

The issue is likely caused by a wrong mergevars alteration in one of the alter hooks.该问题可能是由于其中一个更改挂钩中的错误mergevars更改引起的。 Note variables are passed by reference.注意变量是通过引用传递的。

If you find that $mergevars actually is an array of string (is it seems all good) inside your module alter hook, it means that another contrib module acting after yours (@see module priority) is causing the issue.如果您发现$mergevars实际上是模块更改钩子中的一个字符串数组(看起来一切都很好),则意味着在您的模块之后执行的另一个 contrib 模块(@see 模块优先级)导致了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM