diff --git a/drupal-org.make b/drupal-org.make index 2903120ff3b4b6be99111fea8f200b1ce57c6c61..7458136ab6d92dfd0cd68e303ab01cbf08806af8 100644 --- a/drupal-org.make +++ b/drupal-org.make @@ -268,6 +268,10 @@ projects[module_filter][type] = "module" projects[module_filter][subdir] = "contrib" projects[module_filter][version] = "1.8" +projects[modal_forms][type] = "module" +projects[modal_forms][subdir] = "contrib" +projects[modal_forms][version] = "1.2" + projects[mollom][type] = "module" projects[mollom][subdir] = "contrib" projects[mollom][version] = "2.9" diff --git a/modules/commons/commons_trusted_contacts/commons_trusted_contacts.module b/modules/commons/commons_trusted_contacts/commons_trusted_contacts.module index 1eb7a8c9ca03f18cca3a2463591f71af10078a52..0cb1906a9eec8e6a64bf8d1beaf5aa69f2db29f2 100644 --- a/modules/commons/commons_trusted_contacts/commons_trusted_contacts.module +++ b/modules/commons/commons_trusted_contacts/commons_trusted_contacts.module @@ -7,6 +7,15 @@ include_once 'commons_trusted_contacts.features.inc'; /** + * Implements hook_init(). + */ +function commons_trusted_contacts_init() { + if (module_exists('modal_forms')) { + _commons_trusted_contacts_add_modal_js(); + } +} + +/** * Implements hook_system_info_alter(). */ function commons_trusted_contacts_system_info_alter(&$info, $file, $type) { @@ -107,11 +116,11 @@ 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), + 'access arguments' => array(6), 'type' => MENU_CALLBACK, ); @@ -167,7 +176,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; @@ -182,12 +191,11 @@ function commons_trusted_contacts_module_implements_alter(&$implementations, $ho // and has the same weight, so we need this alter to ensure that // our hook_form_alter() implementation runs after VBO, so that the // elements VBO adds are already present when we alter the form. - if ($hook == 'form_alter') { - $group = $implementations['commons_trusted_contacts']; - unset($implementations['commons_trusted_contacts']); - $implementations['commons_trusted_contacts'] = $group; - } - if ($hook == 'node_presave') { + // We also need to come last in the init function for the modal JS to be added + // Correctly. + if ($hook == 'form_alter' || + $hook == 'node_presave' || + $hook == 'init') { $group = $implementations['commons_trusted_contacts']; unset($implementations['commons_trusted_contacts']); $implementations['commons_trusted_contacts'] = $group; @@ -216,6 +224,13 @@ function commons_trusted_contacts_form_user_admin_settings_alter(&$form, &$form_ * Implements hook_form_alter(). */ function commons_trusted_contacts_form_alter(&$form, &$form_state, $form_id) { + // Remove the text format and title options form messages. + if ($form_id == 'commons_trusted_contacts_messages_popup') { + $form['body']['#title'] = ''; + $form['body']['#resizable'] = FALSE; + $form['body']['#format'] = 'plain_text'; + $form['body']['#after_build'] = array('commons_trusted_contacts_format_access'); + } // Don't allow users to change the recipient of a private message. // In combination with commons_trusted_contacts_privatemsg_write_access(), // we prevent users from sending private messages to users who are not their @@ -335,10 +350,16 @@ function commons_trusted_contacts_field_formatter_view($entity_type, $entity, $f return; } - 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-message-popup-style'), + ), + ); + } } else { if (og_is_member($entity_type, $id, 'user', $account, array(OG_STATE_PENDING))) { @@ -1154,6 +1175,73 @@ function commons_trusted_contacts_operations_load_action_includes() { } /** + * After build callback; Hide format widget from the message body. + */ +function commons_trusted_contacts_format_access($element) { + if (isset($element['format'])) { + $element['format']['#access'] = FALSE; + } + return $element; +} + +/** + * Add the messaging modal JS style if modal_forms module exists. See hook_init + * For more information. + */ +function _commons_trusted_contacts_add_modal_js() { + // Create our own javascript that will be used to theme a modal. + $message_style = array( + 'message-popup-style' => array( + 'modalSize' => array( + 'type' => 'fixed', + 'width' => 525, + 'height' => 250, + ), + 'modalOptions' => array( + 'opacity' => .5, + 'background-color' => '#000', + ), + 'animation' => 'fadeIn', + 'modalTheme' => 'ModalFormsPopup', + ), + ); + drupal_add_js($message_style, 'setting'); +} + +/* + * 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. * * @param $account diff --git a/modules/commons/commons_trusted_contacts/views/handlers/commons_groups_handler_send_message.inc b/modules/commons/commons_trusted_contacts/views/handlers/commons_groups_handler_send_message.inc index cc78effed3e83557d5e915e3cf6b88cb799de533..0a8ab498d914125ec729f7c82e155472452ed0f6 100644 --- a/modules/commons/commons_trusted_contacts/views/handlers/commons_groups_handler_send_message.inc +++ b/modules/commons/commons_trusted_contacts/views/handlers/commons_groups_handler_send_message.inc @@ -5,6 +5,11 @@ class commons_trusted_contacts_handler_send_message extends views_handler_field function render($values) { global $user; - return l(t('Send private message'), 'user/' . $user->uid . '/contacts/messages/popup/' . $values->og_membership_etid); + if (module_exists('modal_forms')) { + return l(t('Send private message'), 'user/' . $user->uid . '/contacts/messages/nojs/popup/' . $values->og_membership_etid, array('attributes' => array('class' => array('ctools-use-modal', 'ctools-modal-message-popup-style')))); + } + else { + return l(t('Send private message'), 'user/' . $user->uid . '/contacts/messages/nojs/popup/' . $values->og_membership_etid); + } } }