Skip to content

Instantly share code, notes, and snippets.

@laurelstreng
Created May 3, 2019 16:26
Show Gist options
  • Save laurelstreng/b75bf81beabf01c1315a5a102f878e6c to your computer and use it in GitHub Desktop.
Save laurelstreng/b75bf81beabf01c1315a5a102f878e6c to your computer and use it in GitHub Desktop.
Drupal 8 Address Field – Reorder subfields in an Address field
// Form alter for the User Registration form
function MODULE_user_form_user_register_form_alter(&$form) {
if (isset($form['field_address'])) {
$form['field_address']['widget'][0]['address']['#after_build'][] = 'wrf_user_address_after_build';
}
}
// Custom function for #after_build
function MODULE_user_address_after_build($element, FormStateInterface $form_state) {
// Move the country field to the bottom
$element['country_code']['#weight'] = '100';
return $element;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment