When editing a user profile or creating a new user, the address form has errors.
1- All countries are shown instead of the list being limited to the selected countries.
2- When a country is chosen, address fields do not update with the correct fields for that country.
When trying to change countries in the address form, the site generates the following error:
------------------------------------
Type php
Message TypeError: key(): Argument #1 ($array) must be of type array, null given in key() (line 369 of /var/www/html/web/core/modules/user/src/AccountForm.php).
Severity Error
Backtrace
#0 /var/www/html/web/core/modules/user/src/AccountForm.php(369): key()
#1 /var/www/html/web/core/lib/Drupal/Core/Entity/ContentEntityForm.php(186): Drupal\user\AccountForm->buildEntity()
#2 [internal function]: Drupal\Core\Entity\ContentEntityForm->validateForm()
#3 /var/www/html/web/core/lib/Drupal/Core/Form/FormValidator.php(82): call_user_func_array()
#4 /var/www/html/web/core/lib/Drupal/Core/Form/FormValidator.php(274): Drupal\Core\Form\FormValidator->executeValidateHandlers()
#5 /var/www/html/web/core/lib/Drupal/Core/Form/FormValidator.php(118): Drupal\Core\Form\FormValidator->doValidateForm()
#6 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(593): Drupal\Core\Form\FormValidator->validateForm()
#7 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(326): Drupal\Core\Form\FormBuilder->processForm()
#8 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
#9 [internal function]: Drupal\Core\Controller\FormController->getContentResult()
#10 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#11 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(637): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#12 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
#13 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#14 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#15 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#16 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
#17 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#18 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#19 /var/www/html/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
#20 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(116): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
#21 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(90): Drupal\page_cache\StackMiddleware\PageCache->pass()
#22 /var/www/html/web/modules/contrib/advban/src/AdvbanMiddleware.php(61): Drupal\page_cache\StackMiddleware\PageCache->handle()
#23 /var/www/html/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\advban\AdvbanMiddleware->handle()
#24 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle()
#25 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#26 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#27 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#28 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#29 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#30 {main}
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | account-address-form-error-patch-3.patch | 532 bytes | jbuttler |
| #3 | account-address-form-error-patch-2.patch | 774 bytes | jbuttler |
| #2 | account-address-form-error-patch-1.patch | 774 bytes | jbuttler |
Issue fork drupal-3590034
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
Comment #2
jbuttler commentedI have created a patch that fixes this issue for me. Patch contents:
diff --git a/core/modules/user/src/AccountForm.php b/core/modules/user/src/AccountForm.php
index b61c281..a72f3a4 100644
--- a/core/modules/user/src/AccountForm.php
+++ b/core/modules/user/src/AccountForm.php
@@ -366,7 +366,7 @@ class AccountForm extends EntityForm {
// If the form state has roles assigned, make sure they are in the expected
// format before saving. This prevents errors when modules alter the form
// element or when multi-step forms / AJAX operations are executed.
- if (is_string(key($form_state->getValue('roles')))) {
+ if (is_string($form_state->getValue('roles') ? key($form_state->getValue('roles')) : '')) {
$form_state->setValue('roles', array_keys(array_filter($form_state->getValue('roles'))));
}
Comment #3
jbuttler commentedThere was an error. Patch updated.
Comment #4
jbuttler commentedPatch 2 failed for me. Trying again with changes.