You are here

function commerce_addressbook_field_attach_form in Commerce Addressbook 7

Implements hook_field_attach_form().

File

./commerce_addressbook.module, line 91
:

Code

function commerce_addressbook_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {

  // Exit if form is not a customer profile.
  if (!in_array($entity_type, commerce_addressbook_enabled_entities())) {
    return;
  }

  // Exit if not on an order.
  if (empty($entity->entity_context) || empty($entity->entity_context['entity_type']) || $entity->entity_context['entity_type'] != 'commerce_order') {
    return;
  }

  // Wrap the entity to be able to fill its fields through AJAX
  $wrapper = $entity_type . '_' . $entity->type . '_wrapper';
  $form['#prefix'] = '<div id="' . str_replace('_', '-', $wrapper) . '">';
  $form['#suffix'] = '</div>';
}