- 🇧🇩Bangladesh shafiqhossain
I faced the similar issue, posted here, https://www.drupal.org/project/drupal/issues/3477465 🐛 TypeError: key(): Argument #1 ($array) must be of type array, null given in key() (line 368 of /public_html/web/core/modules/user/src/AccountForm.php) Active
I checked with new Drupal 10 dump with a image field added into user entity, the issue does not persist there.But For my existing site, I literally uninstalled all custom modules and most of the contributed modules, but still getting issue. So dump the $form_state->getValues() there and see if "roles" values are there, but its not. I got this:
Array ( .... [3] => field_test_picture .... [20] => field_user_other_website [21] => field_user_picture [23] => field_user_state [24] => field_user_twitter [25] => field_user_youtube ..... [26] => path [27] => user_picture [28] => submit [29] => form_build_id [30] => form_token [31] => form_id [32] => contact [33] => field_test_picture_0_upload_button [34] => mail [35] => pass [36] => field_parent_account
- 🇧🇩Bangladesh shafiqhossain
As it mentioned in the AccountForm.php, this process is called twice:
/** * {@inheritdoc} */ public function buildEntity(array $form, FormStateInterface $form_state) { // Change the roles array to a list of enabled roles. // @todo Alter the form state as the form values are directly extracted and // set on the field, which throws an exception as the list requires // numeric keys. Allow to override this per field. As this function is // called twice, we have to prevent it from getting the array keys twice.
I debugged, in the first call "roles" key is there. But in the second call, "roles" is absent.