You are here

function rooms_booking_edit_profile_callback in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

AJAX callback to update "edit profile" link after Customer field changes.

See also

rooms_booking_edit_form()

1 string reference to 'rooms_booking_edit_profile_callback'
rooms_booking_edit_form in modules/rooms_booking/rooms_booking.admin.inc
Form callback: create or edit a booking.

File

modules/rooms_booking/rooms_booking.admin.inc, line 191
Rooms editing UI.

Code

function rooms_booking_edit_profile_callback(&$form, $form_state) {
  if (module_exists('commerce_customer')) {
    $client = explode(':', $form_state['values']['client']);
    if (isset($client[1])) {
      $result = db_select('field_data_commerce_customer_address')
        ->fields('field_data_commerce_customer_address', array(
        'entity_id',
      ))
        ->condition('commerce_customer_address_name_line', $client[0])
        ->condition('entity_id', $client[1])
        ->execute()
        ->fetchField();
      if ($result !== FALSE && user_access('create customer profiles on bookings')) {
        $form['client']['#field_suffix'] = t('<a href="@edit-profile" class="ctools-use-modal">edit profile</a>', array(
          '@edit-profile' => url('admin/rooms/customer-profiles/' . $client[1] . '/edit'),
        ));
      }
      else {
        $form['client']['#field_suffix'] = '';
      }
    }
    else {
      $form['client']['#field_suffix'] = '';
    }
  }
  return render($form['client']);
}