Skip to content
Snippets Groups Projects
Commit 627c5a55 authored by Brian Canini's avatar Brian Canini
Browse files

new module - CUSTOM - google map autofill: autofills google map field in people form

parent 76aa0097
No related branches found
No related tags found
No related merge requests found
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
<?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
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment