I believe we've seen something like this issue before, but in our case, when you save a profile, the following occurs:

Warning: Invalid argument supplied for foreach() in Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDerivatives() (line 102 of core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php).

The issue stems from ldap_authentication/src/Plugin/Derivative/DynamicUserHelpLink.php. The getDerivativeDefinitions() function will call $this->addLink(), but addlink() will set $definitions to NULL (instead of an array) if the following "if" cannot be satisfied:

if (\Drupal::config('ldap_authentication.settings')
      ->get('ldapUserHelpLinkText') && \Drupal::config('ldap_authentication.settings')
      ->get('ldapUserHelpLinkUrl')) { ... }

A simple fix is to return $this->derivatives after the if() rather than inside it.

--- ldap_authentication/src/Plugin/Derivative/DynamicUserHelpLink.php.orig
+++ ldap_authentication/src/Plugin/Derivative/DynamicUserHelpLink.php
@@ -74,8 +74,8 @@
       $this->derivatives['ldap_authentication.show_user_help_link']['title'] = \Drupal::config('ldap_authentication.settings')
         ->get('ldapUserHelpLinkText');
       $this->derivatives['ldap_authentication.show_user_help_link']['route_name'] = 'ldap_authentication.ldap_help_redirect';
-      return $this->derivatives;
     }
+    return $this->derivatives;
   }

 }

Comments

bricas created an issue. See original summary.

  • grahl committed 64fc23f on 8.x-3.x
    Issue #2900950: Invalid argument supplied for foreach() in...
grahl’s picture

Status: Active » Fixed

Hi

Thanks for the bug report. Your resolution would work but looking at it revealed several issues with the deriver here. Namely, the access check was cached and not user dependent and the derivates array was being set in an redundant way.

This commit fixes this, additional testing would be appreciated.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.