function rooms_booking_add_customer_profile in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7
AJAX callback to display a modal form to create a customer profile.
1 string reference to 'rooms_booking_add_customer_profile'
- rooms_booking_menu in modules/
rooms_booking/ rooms_booking.module - Implements hook_menu().
File
- modules/
rooms_booking/ rooms_booking.module, line 273 - Manage Bookings - Bookings are tied to a customer profile and possible a Unit ID and Order ID.
Code
function rooms_booking_add_customer_profile() {
ctools_include('modal');
module_load_include('inc', 'commerce_customer', 'includes/commerce_customer_profile.forms');
$form_state = array(
'title' => t('Add customer'),
'ajax' => TRUE,
'build_info' => array(
'args' => array(
commerce_customer_profile_new('billing', 1),
),
'files' => array(
'commerce_customer' => array(
'module' => 'commerce_customer',
'name' => 'includes/commerce_customer_profile.forms',
'type' => 'inc',
),
),
),
);
// Wrap the form via ctools modal.
$output = ctools_modal_form_wrapper('commerce_customer_customer_profile_form', $form_state);
if ($form_state['executed']) {
$form['client'] = array(
'#type' => 'textfield',
'#title' => t('Customer'),
'#maxlength' => 60,
'#autocomplete_path' => 'admin/rooms/bookings/customers',
'#value' => $form_state['build_info']['args'][0]->commerce_customer_address[LANGUAGE_NONE][0]['name_line'],
'#weight' => -1,
'#required' => TRUE,
'#prefix' => '<div class="form-wrapper" id="edit-customer-wrapper">',
'#suffix' => '</div>',
'#id' => 'edit-client',
'#name' => 'client',
);
if (module_exists('commerce_customer')) {
ctools_include('modal');
ctools_modal_add_js();
$form['client']['#description'] = t('Customer profiles are saved in the <a href="@store-profile">store</a>. Search for an existing one by typing the customer name or <a href="@profile-create" class="ctools-use-modal">create a new profile</a>.', array(
'@store-profile' => url('admin/commerce/customer-profiles'),
'@profile-create' => url('admin/rooms/add_customers'),
));
if (isset($form_state['build_info']['args'][0]->profile_id)) {
$form['client']['#field_suffix'] = t('<a href="@edit-profile" class="ctools-use-modal">edit profile</a>', array(
'@edit-profile' => url('admin/rooms/customer-profiles/' . $form_state['build_info']['args'][0]->profile_id . '/edit'),
));
}
}
$output = array(
ctools_modal_command_dismiss(),
ajax_command_replace('#edit-customer-wrapper', drupal_render($form['client'])),
);
}
print ajax_render($output);
exit;
}