Setting #disabled on Address element is ignored by Country element

Created on 25 July 2025, 8 days ago

Problem/Motivation

Prior to version 2.0.3, you could set #disabled to TRUE on the parent address element in a form alter hook, and all child elements would be disabled. From 2.0.3 onwards the country_code element is no longer disabled.

The fix introduced in 2.0.3 for issue 📌 Give support for '#diasabled property in address_country form element Active is the cause for this bug. The new #disabled declaration on the country_code element causes the declaration on the parent address element to be ignored.

Steps to reproduce

  1. Add an address field to a content type.
  2. Add a form alter hook and set #disabled to true on the address element of the address field (see example code below).
  3. Visit the form and you should see the Country element is not disabled when it should be.
  4. If you create a node with an address set, on the edit form you should see all the Address fields are disabled except for the Country field.
function address_test_form_node_article_form_alter(&$form, FormStateInterface $form_state): void {
  $form['field_address']['widget'][0]['address']['#disabled'] = TRUE;
}

function address_test_form_node_article_edit_form_alter(&$form, FormStateInterface $form_state): void {
  $form['field_address']['widget'][0]['address']['#disabled'] = TRUE;
}

Proposed resolution

  • Add testing to ensure setting #disabled to TRUE on the address element results in all child elements being disabled
  • Refactor \Drupal\address\Element\Address::processAddress() to set #disabled on the country_code element based on the parent address element.
🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇨🇦Canada tame4tex

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