diff --git a/modules/commons/commons_trusted_contacts/commons_trusted_contacts.module b/modules/commons/commons_trusted_contacts/commons_trusted_contacts.module index b16bfac..632d545 100644 --- a/modules/commons/commons_trusted_contacts/commons_trusted_contacts.module +++ b/modules/commons/commons_trusted_contacts/commons_trusted_contacts.module @@ -107,9 +107,9 @@ function commons_trusted_contacts_menu() { 'type' => MENU_CALLBACK, ); - $items['user/%user/contacts/messages/popup/%user'] = array( - 'page callback' => 'drupal_get_form', - 'page arguments' => array('commons_trusted_contacts_messages_popup', 5), + $items['user/%user/contacts/messages/%ctools_js/popup/%user'] = array( + 'page callback' => 'commons_trusted_contacts_messages_popup_wrapper', + 'page arguments' => array(4, 6), 'access callback' => 'commons_trusted_contacts_privatemsg_write_access', 'access arguments' => array(5), 'type' => MENU_CALLBACK, @@ -167,7 +167,7 @@ function commons_trusted_contacts_menu_alter(&$items) { */ function commons_trusted_contacts_admin_paths() { $paths = array( - 'user/*/contacts/messages/popup/*' => TRUE, + 'user/*/contacts/messages/*/popup/*' => TRUE, ); return $paths; @@ -324,7 +324,14 @@ function commons_trusted_contacts_field_formatter_view($entity_type, $entity, $f if ($user_is_active_member) { $links['title'] = t('Message'); - $links['href'] = 'user/' . $user->uid . '/contacts/messages/popup/' . $id; + $links['href'] = 'user/' . $user->uid . '/contacts/messages/nojs/popup/' . $id; + if (module_exists('modal_forms')) { + $links['options'] = array( + 'attributes' => array( + 'class' => array('ctools-use-modal', 'ctools-modal-modal-popup-medium'), + ), + ); + } } else { if (og_is_member($entity_type, $id, 'user', $account, array(OG_STATE_PENDING))) { @@ -1051,6 +1058,39 @@ function commons_trusted_contacts_operations_load_action_includes() { return $files; } +/* + * A modal user login callback. + */ +function commons_trusted_contacts_messages_popup_wrapper($js = NULL, $account) { + // Fall back if $js is not set. + if (!$js) { + return drupal_get_form('commons_trusted_contacts_messages_popup', $account); + } + + ctools_include('modal'); + ctools_include('ajax'); + $form_state = array( + // 'title' => t('Send message'), + 'ajax' => TRUE, + 'build_info' => array('args' => array($account)), + ); + + $output = ctools_modal_form_wrapper('commons_trusted_contacts_messages_popup', $form_state, $account); + if (!empty($form_state['executed'])) { + // We'll just overwrite the form output if it was successful. + $output = array(); + ctools_add_js('ajax-responder'); + if (isset($_GET['destination'])) { + $output[] = ctools_ajax_command_redirect($_GET['destination']); + } + else { + $output[] = ctools_ajax_command_reload(); + } + } + print ajax_render($output); +} + + /** * Menu callback; Write Private Message popup form. *