- Issue created by @eduardo morales alberti
- Merge request !25Issue #3543263 by eduardo morales alberti: Undefined array key "#dial_code" → (Open) created by eduardo morales alberti
After updating the phone_international module to version 4.0.0, a "Warning: Undefined array key "#dial_code"" error is thrown on forms that use the phone field.
The full error trace is:
Warning: Undefined array key "#dial_code" in Drupal\phone_international\Element\PhoneInternationalElement::preRenderPhoneInternational() (line 125 of modules/contrib/phone_international/src/Element/PhoneInternationalElement.php). Drupal\phone_international\Element\PhoneInternationalElement::preRenderPhoneInternational() call_user_func_array() (Line: 113) Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 917) Drupal\Core\Render\Renderer->doCallback() (Line: 441) Drupal\Core\Render\Renderer->doRender() (Line: 530) Drupal\Core\Render\Renderer->doRender() (Line: 257) Drupal\Core\Render\Renderer->render() (Line: 238) Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent{closure}() (Line: 668) Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 231) Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 128) Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90) Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray() call_user_func() (Line: 111) Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 186) Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76) Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53) Drupal\Core\StackMiddleware\Session->handle() (Line: 48) Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28) Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 53) Asm89\Stack\Cors->handle() (Line: 48) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36) Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51) Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741) Drupal\Core\DrupalKernel->handle() (Line: 19)
This regression appears to be a side effect of the new dial-code functionality introduced in the 3bbc571a2e604e52153856e1871e6237186fc58f commit, which was part of issue 3460732 📌 Option to enable country dial code in the input field Needs review .
The root cause is that existing phone fields from before the 4.0.0 update do not have the new dial-code key in their configuration, causing the preRenderPhoneInternational() method to throw a warning.
The issue can be resolved by providing a hook update that iterates over all existing phone_international fields and adds the new dial-code setting to their configuration, preventing the warning. This will ensure backward compatibility and a smooth upgrade path for existing sites.
None. This is a backend fix for a data model change.
None.
A hook update is required to modify the existing field configuration to add the new dial_code setting, preventing the "Undefined array key" warning.
Active
4.0
Code