# Address field #after\_build

It's tricky to get at address fields with a standard form alter. I discovered, you can create an after build function to dig into the nested address field arrays. First create the custom function

```php
/**
 * Implements hook_form_alter().
 */
function dev_patterns_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_register_form') {
    // Custom after build for address elements.
    $form['field_address']['widget'][0]['address']['#after_build'][] = '_dev_patterns_register_alter_attr';
  }
}
```

�Next, use the new custom function to alter address fields as you normally would.&#x20;

```php
/**
 * Implements custom function: _gd_quote_register_alter_attr.
 */
function _dev_patterns_register_alter_attr($element, $form_state) {
  // Alter various elements of the reg form address field.
  $element["address_line1"]["#title"] = t('Address');
  $element["address_line2"]["#title"] = t('Address line 2');
  return $element;
}
```

�


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://danny-englander.gitbook.io/dev-patterns/drupal-8/form-alter/address-field-after_build.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
