Skip to content
Snippets Groups Projects
Commit 438a67ca authored by Bohdan Artemchuk's avatar Bohdan Artemchuk Committed by Bohdan Artemchuk
Browse files

Issue #3254806 by bohart, dev.tim: Fixed `Invalid argument supplied for...

Issue #3254806 by bohart, dev.tim: Fixed `Invalid argument supplied for foreach()` errors for null value of REROUTE_EMAIL_ROLES
parent 7c24a874
No related branches found
No related tags found
No related merge requests found
......@@ -312,7 +312,7 @@ function reroute_email_check_email_by_permission(string $email): bool {
/** @var \Drupal\user\UserInterface $account */
$account = reset($users);
$roles = \Drupal::config('reroute_email.settings')->get(REROUTE_EMAIL_ROLES);
$roles = (array) \Drupal::config('reroute_email.settings')->get(REROUTE_EMAIL_ROLES);
foreach ($roles as $role) {
if ($account->hasRole($role)) {
return TRUE;
......
......@@ -159,7 +159,7 @@ class SettingsForm extends ConfigFormBase implements TrustedCallbackInterface {
'#title' => $this->t('Skip email rerouting for roles:'),
'#description' => $this->t("Emails that belong to users with selected roles won't be rerouted."),
'#options' => $roles,
'#default_value' => $this->rerouteConfig->get(REROUTE_EMAIL_ROLES),
'#default_value' => (array) $this->rerouteConfig->get(REROUTE_EMAIL_ROLES),
];
$form[REROUTE_EMAIL_DESCRIPTION] = [
......
  • Just throwing it out there that the $roles definition could be moved up to the top of the function and checked for first.

    Then you'd save the user lookup if role was null.

  • Actually I think this issue is with the submitForm function.

    SettingsForm.php, line 292, the REROUTE_EMAIL_ROLES is defined. That form value can be empty, so we default to an empty array, since its going to hit that loop.

    ->set(REROUTE_EMAIL_ROLES, array_values(array_filter($form_state->getValue(REROUTE_EMAIL_ROLES)) ?? []))

    This fixes the default_value and the loop issue at the same time.

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment