Here's the error that is thrown when trying to add a new user:

Notice: Array to string conversion in form_process_checkbox() (line 1380 of core/includes/form.inc).

To reproduce

  • Install the latest HEAD
  • Go to admin/people
  • Hit the Add user button (admin/people/create)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andrei.dincu’s picture

FileSize
27.38 KB

This is the notice you will receive when a new user is added.

andrei.dincu’s picture

FileSize
755 bytes

Check if $value is an array and transform it to string using implode().

andrei.dincu’s picture

Status: Active » Needs review
rahulbile’s picture

Status: Needs review » Reviewed & tested by the community

Patch seems to fix the issue properly.

webchick’s picture

Priority: Minor » Normal
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Hm. We should be able to add a test that catches this. In fact, I'm mystified how existing tests are not catching this... adding a user from admin/people is not exactly the outer limits.

ACF’s picture

FileSize
542 bytes

Just investigated why the UserCreateTest wasn't picking up the error, as on the face of it it should have been. It turns out it's because contact module isn't enabled in the test. Have added a patch which will pick up the error, not sure this is a change that needs to be committed.

ACF’s picture

Status: Needs work » Needs review

To show test failing.

Status: Needs review » Needs work

The last submitted patch, 6: 2231495-test-6.patch, failed testing.

ACF’s picture

Status: Needs work » Needs review
FileSize
1.3 KB

Worked out that the problem is being caused by contact_form_user_form_alter. The account_data default for the contact form is set as an array if their is no account id for the form (i.e. when there is an empty form). UserData->get returns the array which I assume is correct so I made a fix in the form_alter function.

I've left the 'contact' enabled in the usercreate simpletest to pick up the error. Wonder whether should write a new test for the contact module which checks that field, any thoughts?

filijonka’s picture

Issue tags: -Needs tests

hi

checked this one and if the change to the test is added without patch the test fails which is what we want.
When adding the patch it works as it is supposed to do and test passes.

filijonka’s picture

Status: Needs review » Reviewed & tested by the community

I'm feeling lucky..I'm setting this to done..it does the job as far as I'm concerned..can't see any trouble with it

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 562adda and pushed to 8.x. Thanks!

  • Commit 562adda on 8.x by alexpott:
    Issue #2231495 by ACF, andrei.dincu: Array to string conversion error...
marcingy’s picture

This is a duplicate of #2030743: Improve tests for user form alters in contact module which has more far reaching tests :(

anavarre’s picture

Status: Fixed » Closed (fixed)

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

YesCT’s picture

+++ b/core/modules/user/lib/Drupal/user/Tests/UserCreateTest.php
@@ -19,7 +19,7 @@ class UserCreateTest extends WebTestBase {
-  public static $modules = array('image');
+  public static $modules = array('image', 'contact');

#2030743: Improve tests for user form alters in contact module is going to undo this and add actual test coverage as webchick asked for.