Undefined array key "#dial_code"

Created on 27 August 2025, about 1 month ago

Problem/Motivation

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.

Steps to reproduce

  1. Have a Drupal installation with the phone_international module installed on a version older than 4.0.0.
  2. Ensure there is an existing phone field configured on a content type or form.
  3. Update the phone_international module to version 4.0.0 using Composer.
  4. Navigate to a page that displays the phone field (e.g., a node add form or edit form).
  5. Observe the "Undefined array key" warning.

Proposed resolution

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.

Remaining tasks

  • Review the proposed resolution.
  • Create a patch that implements a new hook update function.
  • Test the patch to confirm the warning is resolved and that the field functionality remains intact.

User interface changes

None. This is a backend fix for a data model change.

API changes

None.

Data model changes

A hook update is required to modify the existing field configuration to add the new dial_code setting, preventing the "Undefined array key" warning.

🐛 Bug report
Status

Active

Version

4.0

Component

Code

Created by

🇪🇸Spain eduardo morales alberti Spain, 🇪🇺

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024