diff --git a/web/modules/custom/google_map_autofill/google_map_autofill.info.yml b/web/modules/custom/google_map_autofill/google_map_autofill.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..bfdb370652ec37b16ed13cb06814d4a924aa9e70 --- /dev/null +++ b/web/modules/custom/google_map_autofill/google_map_autofill.info.yml @@ -0,0 +1,7 @@ +name: Google Map Autofill +description: 'Automatically fills in the Google Map field with content from the Address field in User' +core: 8.x +type: module +package: ASC Tech +dependencies: + - drupal:user diff --git a/web/modules/custom/google_map_autofill/google_map_autofill.module b/web/modules/custom/google_map_autofill/google_map_autofill.module new file mode 100644 index 0000000000000000000000000000000000000000..aa704bdece57d28e17de3c575b346e2b1fd48c58 --- /dev/null +++ b/web/modules/custom/google_map_autofill/google_map_autofill.module @@ -0,0 +1,19 @@ +<?php +function google_map_autofill_form_alter(&$form, &$form_state, $form_id) { + if(in_array($form_id,['user_form','user_edit_form'])) { + $form['field_google_map']['#disabled'] = 'disabled'; + } + if(in_array($form_id,['user-register-form','user_register_form'])) { + $form['field_google_map']['#disabled'] = 'disabled'; + } +} + +function google_map_autofill_entity_presave(Drupal\Core\Entity\EntityInterface $entity) { + if($entity->bundle() == "user"){ + //get content from field_address and check it for linebreaks; if linebreaks exist replace them with single space + $address = trim(preg_replace('/\s+/', ' ', $entity->field_address->value)); + //set field_google_map value to equal field_address + $entity->field_google_map->value = $address; + //save is done automatically + } +}