Problem/Motivation

There are lot of warnings related to the rules that contain tokens inside. The issue is on the token replace logic inside of the method processVariables() and processTokens() of the class src/Plugin/BusinessRulesItemPluginBase.php

Warning: preg_match_all() expects parameter 2 to be string, array given in Drupal\Core\Utility\Token->scan() (line 240 of /app/public/core/lib/Drupal/Core/Utility/Token.php)
#0 /app/public/core/includes/bootstrap.inc(312): _drupal_error_handler_real()

Steps to reproduce

Provide a condition, for example sending an email with tokens inside, when a node is saved.

Proposed resolution

I've written a patch that fixes the warnings.

Remaining tasks

Need to check it well.

User interface changes

No changes.

API changes

No changes.

Data model changes

No changes.

Command icon 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

andrei.vesterli created an issue. See original summary.

andrei.vesterli’s picture

Issue summary: View changes
mlahde’s picture

When using Conditions to send emails after an entity save, I got multiple warnings and notices:

Error message
Close
Warning: preg_match_all() expects parameter 2 to be string, array given in Drupal\business_rules\Plugin\BusinessRulesItemPluginBase->processVariables() (line 157 of modules/contrib/business_rules/src/Plugin/BusinessRulesItemPluginBase.php).
Warning: preg_match_all() expects parameter 2 to be string, array given in Drupal\Core\Utility\Token->scan() (line 240 of core/lib/Drupal/Core/Utility/Token.php).
Notice: Trying to access array offset on value of type null in Drupal\Core\Utility\Token->scan() (line 248 of core/lib/Drupal/Core/Utility/Token.php).
Notice: Trying to access array offset on value of type null in Drupal\Core\Utility\Token->scan() (line 249 of core/lib/Drupal/Core/Utility/Token.php).
Warning: count(): Parameter must be an array or an object that implements Countable in Drupal\Core\Utility\Token->scan() (line 255 of core/lib/Drupal/Core/Utility/Token.php).
Warning: preg_match_all() expects parameter 2 to be string, array given in Drupal\Core\Utility\Token->scan() (line 240 of core/lib/Drupal/Core/Utility/Token.php).
Notice: Trying to access array offset on value of type null in Drupal\Core\Utility\Token->scan() (line 248 of core/lib/Drupal/Core/Utility/Token.php).
Notice: Trying to access array offset on value of type null in Drupal\Core\Utility\Token->scan() (line 249 of core/lib/Drupal/Core/Utility/Token.php).
Warning: count(): Parameter must be an array or an object that implements Countable in Drupal\Core\Utility\Token->scan() (line 255 of core/lib/Drupal/Core/Utility/Token.php).

The actual email sending works correctly when the Condition is met the email get sent. The warnings don't emerge when I compare a typical Text (Plain) field's original and current value, but only when comparing a Text (Plain) or a Text (plain, long) fields that are grouped as a Field group in the "Manage form display" (/admin/structure/types/manage//form-display)

The provided patch seems to fix this.

andrei.vesterli’s picture

Priority: Normal » Major

Hi there

Will any maintainer take a look at this small issue? I can prepare a fork for it too.