How to set a placeholder text for the proximity search field

You, DrupalGeolcation
Back

In Drupal 7 there are 3 popular ways to create proximity search for your content or entity.

1. Combination of Geofield, GeoPHP and geoCoder with Addressfield

2. Geolocation and Geolocation proximity (As of today only D8 ready version)

3. Location module (This uses a completely different approach and very unpopular now)

So in this example I'm going to show you how to add placeholder text to the Geofield element. Since it is an Drupal FAPI element we need to use it's process function to alter it.

/**
 * Implements hook_element_info_alter()
 */
function MODULENAME_element_info_alter(&$type) {
  if (isset($type['geofield_proximity']['#process'])) {
    $type['geofield_proximity']['#process'][] = '_MYCUSTOM_element_process';
  }
}
/*
 * Custom process function
 */
function _MYCUSTOM_element_process($element, &$form_state, $form) {
  $element['origin']['#attributes']['placeholder'] = t('Enter zip code or street address');
  return $element;
}
© Heshan Wanigasooriya.RSS

🍪 This site does not track you.