Problem/Motivation
I want to send an invitation, I get an error after submit:
Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null: INSERT INTO "users_field_data" ("uid", "langcode", "preferred_langcode", "preferred_admin_langcode", "name", "pass", "mail", "timezone", "status", "created", "changed", "access", "login", "init", "default_langcode", "rh_action", "rh_redirect", "rh_redirect_response", "rh_redirect_fallback_action")
Steps to reproduce
- Go to "/group/%/content/add/group_invitation"
- Fill "name" and "Email", click "Submit"
Comments
Comment #2
lobsterr commentedAssume name is custom field you have on group content type for invitation plugin ?
We don't insert any user on submit of this form, I guess some custom code is executed.
I just tested it on the fresh installation it works as it should. Please double check your side
Comment #3
antiden commentedHi,
ok, find problem. I have installed module: remove_username and that caused the error, because this module is removing the 'name' (username) field from the user management forms.
Your module is working well.
With regards.
Comment #4
lobsterr commentedGlad you find the issue! Cheers
Comment #5
johnnydarkko commented@antiden - What did you end up doing? We're using the same combination of modules. I found that when I remove the presave hook in the remove_username module, the invitation is successfully created. I can't quite figure out what is causing the conflict between this module and the remove_username module...
Comment #6
johnnydarkko commentedAha! There is no email value in the `$user` object.
The presave is setting a null value to the name...
Comment #7
johnnydarkko commentedFound that after the group membership is invoked by the ginvite module and is saved into the database, an anonymous user object is passed into a user save call.
Source: `web/modules/contrib/group/src/Entity/GroupRelationship.php line 262.`
Before the anonymous user is saved, the remove_username attempts to copy the email value (in this case, NULL) to the username value, the database error occurs.
I created an issue in the remove_username module that would prevent this from happening: https://www.drupal.org/project/remove_username/issues/3396469
Comment #8
blade_ukraine commentedIt's also can happen because of the next issue https://www.drupal.org/project/email_registration/issues/3461071