I need to clear any data from an address field's values (administrative area, etc.)

In my custom submit hanlder for node form, I know I can use something like below for a standard field:

  $form_state->setValue('field_alternate_phone', [['value' => 'NEW VALUE']]);

But I cannot figure out how to change the value of a nested address field where the values are something like:

enter image description here

I've solutions similar to below but nothing is working:

$form_state->setValue('field_service_location', [
    ['address' => ['organization' => 'test22111']]
  • Have you tried with $form_state->setValue(['field_service_location'][0]['address']['organization'], 'your value here'). As pointed in the documentation, the key for setValue could be either a string for a direct field or an array for nested field. Reference here: api.drupal.org/api/drupal/…
    – itsandev
    Jun 13, 2023 at 16:02


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.