Problem/Motivation

TypeError: Argument 1 passed to Drupal\ldap_servers\LdapBaseManager::setServer() must be an instance of Drupal\ldap_servers\Entity\Server, string given, called in /web/modules/contrib/ldap/ldap_user/src/Form/LdapUserTestForm.php on line 176 in Drupal\ldap_servers\LdapBaseManager->setServer() (line 113 of /web/modules/contrib/ldap/ldap_servers/src/LdapBaseManager.php)
#0 /web/modules/contrib/ldap/ldap_user/src/Form/LdapUserTestForm.php(176): Drupal\ldap_servers\LdapBaseManager->setServer('xxx')

Steps to reproduce

  1. navigate to /admin/config/people/ldap/user/test
  2. enter Drupal username
  3. Select any of the Actions/Event Handler to Test

Proposed resolution

  • Fix $this->ldapUserManager->setServer() calls in /ldap/ldap_user/src/Form/LdapUserTestForm.php. Currently passing value from configFactory which will always be a string

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#7 3227025-7.patch1.04 KBlarisse

Issue fork ldap-3227025

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

vetchneons created an issue. See original summary.

larisse’s picture

I'm not able to reproduce this error. What Drupal version are you using?

luongosb’s picture

Drupal 9.2.3. It is happening on every site I have upgraded from Drupal 8 and LDAP 8.x-3.0-beta to 8.x-4.0-beta.

joegl made their first commit to this issue’s fork.

joegl’s picture

I was just trying to preview my comment and then saved it and for some reason I created a fork?

joegl’s picture

I've poked at the code a little.

The `LdapUserManager` class extends the `LdapBaseManager` which has the following two methods:

1. `setServer()` (expects a Entity\Server object as argument)
2. `setServerById()` (expects the id of an Entity\Server object)

In the admin form there is a config value for `ldap_user.settings` called `drupalAcctProvisionServer`. This is a radio field set a string value of the server name.

This `drupalAcctProvisionServer`config value is getting loaded into BOTH of the above methods directly in many places throughout the code, and from what I can tell should be throwing errors everywhere:

In `ldap_user/ldap_user.module` it uses `SetServerById()`:
$ldap_user_manager->setServerById($config->get('drupalAcctProvisionServer'));

In `ldap_user/src/Form/LdapUserTestForm.php` it uses `SetServer()`:
$this->ldapUserManager->setServer($config['drupalAcctProvisionServer']);
This is the line of code mentioned in this issue.

In `ldap_user/src/Processor/DrupalUserProcessor.php` it loads the server this way:

$ldap_server = $this->entityTypeManager
      ->getStorage('ldap_server')
      ->load($this->config->get('drupalAcctProvisionServer'));

There are also a lot of files that setup a $server property on the class (as a strict Entity\Server object type) and then load it like this:
$server = $this->config->get('drupalAcctProvisionServer');

larisse’s picture

Status: Active » Needs review
StatusFileSize
new1.04 KB

Hi! Can you test if this patch will work, please?

luongosb’s picture

I applied the patch, but it didn't resolve the issue. Same error. The issue I am having is as mentioned in the issue and in #6:

In `ldap_user/src/Form/LdapUserTestForm.php` it uses `SetServer()`:
$this->ldapUserManager->setServer($config['drupalAcctProvisionServer']);
larisse’s picture

Status: Needs review » Needs work
luongosb’s picture

Just tested this on a new install and ran into the error.

grahl’s picture

Priority: Major » Normal
Status: Needs work » Fixed

While we have this test form for backwards compatibility under /admin/config/people/ldap/user/test it hasn't received much attention and is not really recommended as a primary debugging tool (see the ample warnings on that page) and the server test page is often a better tool.

Apparently it wasn't kept up to date with schema changes and issues crept in. Combining joegl's input and larisse's patch should be sufficient now.

Please reopen if you can still reproduce this on latest dev.

  • grahl committed 07745bc on 8.x-4.x authored by larisse
    Issue #3227025 by larisse, joegl: TypeError: Argument 1 passed to Drupal...

  • grahl committed 07745bc on 8.x-4.x authored by larisse
    Issue #3227025 by larisse, joegl: TypeError: Argument 1 passed to Drupal...
luongosb’s picture

Thanks, grahl. The commit resolved the issue.

Status: Fixed » Closed (fixed)

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