Autocomplete By Zip Code

The admin of a Drupal site enters and updates many addresses every day. For every contact and organization account on their site, they have a city, state, zip code, county, and region. Really, the address fields are just redundant information. Everything can be gleaned from the zip code. So, in an effort to become more efficient and reduce data entry errors, the client requested that the city, state, county, and region fields autocomplete by entering the zip code.

Encrypting Fields on an Entity

Recently, a client had a need to store social security numbers in a Drupal site.  It wasn't the full SSN, just the last 4 digits, but I still wasn't comfortable storing it in plain text in case the database (God forbid!) was ever compromised.

Sanitize emails in db

drush sqlq "UPDATE users SET mail = concat('myaddr+', replace(mail, '@', '_'), '@testdomain.org') WHERE uid > 0 AND instr(mail, '@testdomain.org') = 0;" && drush upwd --password=password admin

Returns a map of field names and vocabularies they can reference

function _get_tax_term_fields_map() {
  static $map;
  if (isset($map)) {
    return $map;

  // First, find all taxonomy term fields.
  foreach (field_info_fields() as $field) {
    if ('taxonomy_term_reference' === $field['type']) {
      $all[] = $field;

  // Next, build a map, keyed by the field name.
  foreach ($all as $field) {
    foreach ($field['settings']['allowed_values'] as $vocab_info) {

Loop through a wrapper entity's properties

function _wrapper_debug($w) {
  $values = array();
  foreach ($w->getPropertyInfo() as $key => $val) {
    $values[$key] = $w->$key->value();
  return $values;


Set up xdebug with Vagrant

1. Find out what the IP address of gateway is with “route -n”
2. Edit xdebug.ini at /etc/php5/conf.d

Printing to terminal with drush

foreach(debug_backtrace() as $item) {
  if ($item['function'] == 'webwise_eck_contact_field_extra_fields') {
Subscribe to RSS - Drupal