Created
May 3, 2019 16:26
-
-
Save laurelstreng/b75bf81beabf01c1315a5a102f878e6c to your computer and use it in GitHub Desktop.
Drupal 8 Address Field – Reorder subfields in an Address field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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