You are here

entityreference_autofill_addressfield.module in Entity reference autofill 7

Entity reference autofill addressfield module.

File

entityreference_autofill_addressfield/entityreference_autofill_addressfield.module
View source
<?php

/**
 * @file
 * Entity reference autofill addressfield module.
 */

/**
 * Implements hook_entityreference_autofill_fill_items_alter().
 */
function entityreference_autofill_addressfield_entityreference_autofill_fill_items_alter(&$form_state, $context) {

  // Add entityreference autofill support to addressfield module.
  if ($context['field']['type'] == 'addressfield') {

    // Replace the addressfield's form input value with referenced value(s).
    // @see addressfield_field_widget_form()
    $parents = array_merge(array(
      'input',
    ), $context['form']['#parents'], array(
      $context['field']['field_name'],
      $context['langcode'],
    ));
    drupal_array_set_nested_value($form_state, $parents, $context['items']);
  }
}