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

  1. Go to "/group/%/content/add/group_invitation"
  2. Fill "name" and "Email", click "Submit"
CommentFileSizeAuthor
#6 image.png85.18 KBjohnnydarkko

Comments

antiden created an issue. See original summary.

lobsterr’s picture

Status: Active » Postponed (maintainer needs more info)

Assume 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

antiden’s picture

Hi,

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.

lobsterr’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Glad you find the issue! Cheers

johnnydarkko’s picture

@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...

johnnydarkko’s picture

StatusFileSize
new85.18 KB

Aha! There is no email value in the `$user` object.

no email

The presave is setting a null value to the name...

/**
 * Implements hook_ENTITY_TYPE_presave().
 */
function remove_username_user_presave(UserInterface $user) {
  $user->setUsername($user->getEmail());
}
johnnydarkko’s picture

Found 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

blade_ukraine’s picture

It's also can happen because of the next issue https://www.drupal.org/project/email_registration/issues/3461071