You are here

function hook_entityreference_autofill_fill_items_alter in Entity reference autofill 7

Alter the form state before rendering an autofill field.

Parameters

array &$form_state: The current form state for the entity form.

array $context: Field context variables.

  • field: The field info array of the field about to be populated.
  • form: The entity form's form API array.
  • instance: The instance of the field.
  • items: The $items belonging to field_name in the referenced entity.
  • langcode: The $langcode.
  • reference_field_name: The name of the entityreference autofill-enabled field that called this autofill request.
1 function implements hook_entityreference_autofill_fill_items_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

entityreference_autofill_addressfield_entityreference_autofill_fill_items_alter in entityreference_autofill_addressfield/entityreference_autofill_addressfield.module
Implements hook_entityreference_autofill_fill_items_alter().
1 invocation of hook_entityreference_autofill_fill_items_alter()
entityreference_autofill_populate_form_by_field in ./entityreference_autofill.module
Populate other form fields with respect to this module's field settings.

File

./entityreference_autofill.api.php, line 43
Hook documentation for the Entity reference autofill module.

Code

function hook_entityreference_autofill_fill_items_alter(&$form_state, $context) {

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

    // Generate element key for addressfield form state.
    // @see addressfield_field_widget_form()
    $element_key_parts = array(
      $context['instance']['entity_type'],
      $context['instance']['bundle'],
      $context['field']['field_name'],
      $context['langcode'],
    );
    $element_key_base = implode('|', $element_key_parts);

    // Add form_state data for each addressfield value
    // from referenced entity.
    foreach ($context['items'] as $delta => $item) {
      $element_key = $element_key_base . '|' . $delta;

      // Add item to addressfield form_state.
      $form_state['addressfield'][$element_key] = $item;
    }
  }
}