diff --git a/README.md b/README.md index ad61d89..5ebd7a0 100755 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ The message_private module requires the following modules: * Message Notify (https://drupal.org/project/message_notify) * Entity API (https://www.drupal.org/project/entity) * Entity Reference (https://www.drupal.org/project/entityreference) + * Entityreference Prepopulate (https://www.drupal.org/project/entityreference_prepopulate) * Ctools (https://www.drupal.org/project/ctools) * Views (https://www.drupal.org/project/views) * Token (https://www.drupal.org/project/token @@ -67,7 +68,7 @@ Message Private View. Email Notifications: Email notifications are sent using message_notify module to users referenced by the field_message_user_ref field and for all group members of the groups -referenced by field_message_groups_ref if using message_private_og. Users can +referenced by field_message_group_ref if using message_private_og. Users can disable email notifications using the checkbox field field_private_message_notify attached to the user entity, on their profile. The message notifications can be turned off globally on the module settings form. @@ -84,7 +85,7 @@ When using the Message Private OG sub-module, the Group Messages display has a contextual filter which filters by group ID of the logged in user. This is developed taking into account that a content type called "Group" exists for all Group instances. Anything other than this setup requires user customisation. You -must manually set the field_message_groups_ref contextual filter to use group +must manually set the field_message_group_ref contextual filter to use group bundle to enable group filter on views. HOW TO USE @@ -115,20 +116,17 @@ CAPTCHA method: https://www.drupal.org/project/recaptcha DEVELOPMENT AND TEST ------------------- - * Add dependency to entityreference_prepopulate and add local action to create - message to user on profile and message : https://www.drupal.org/node/2393915 +-------------------- * Create og permissions and permission checking for private messages. * Create global message_private_og permission - sending message to all groups. ------------------------------------------------------------------------------- Work above required before releasing 1st beta release. ------------------------------------------------------------------------------- * Threads can be created using entity reference field on a private message, - which reference the message being replied to. A new permission to reply to - messages can be created if necessary. An admin screen can be used to enable - or disable threads to turn on/off replies on all private messages (Reply, - Reply All). A tpl.php template and perhaps a css file will need to be added - for indentation / presentation. + which reference the message being replied to. An admin setting can be used to + enable or disable threads to turn on/off replies on all private messages + (Reply, Reply All). A tpl.php template and perhaps a css file will need to be + added for indentation / presentation. * Flag module on user entity to block/unblock users from messaging them * Flag module on message entity to show/hide messages from users own display * Integrate with rolereference module or similar to provide sending to users diff --git a/message_private.info b/message_private.info index 4af7324..5502e5b 100644 --- a/message_private.info +++ b/message_private.info @@ -7,6 +7,7 @@ dependencies[] = message_ui dependencies[] = message_notify dependencies[] = entity dependencies[] = entityreference +dependencies[] = entityreference_prepopulate dependencies[] = ctools dependencies[] = views dependencies[] = token diff --git a/message_private.install b/message_private.install index 3663d04..e7e72bd 100644 --- a/message_private.install +++ b/message_private.install @@ -297,6 +297,19 @@ function message_private_install() { 'label' => $t('Users'), 'required' => 1, 'settings' => array( + 'behaviors' => array( + 'prepopulate' => array( + 'action' => 'none', + 'action_on_edit' => 0, + 'fallback' => 'none', + 'providers' => array( + 'og_context' => FALSE, + 'url' => 1, + ), + 'skip_perm' => 0, + 'status' => 1, + ), + ), 'user_register_form' => FALSE, ), 'widget' => array( @@ -324,9 +337,8 @@ function message_private_install() { 'display' => array( 'default' => array( 'label' => 'above', - 'module' => 'list', 'settings' => array(), - 'type' => 'list_default', + 'type' => 'hidden', 'weight' => 1, ), ), diff --git a/message_private.module b/message_private.module index 022e8a5..284238a 100755 --- a/message_private.module +++ b/message_private.module @@ -143,6 +143,24 @@ function message_private_menu_local_tasks_alter(&$data, $router_item, $root_path global $user; switch ($root_path) { + case 'user/%': + // Add a 'Create a new message for %user' action link. + if (is_array($router_item['page_arguments'])) { + $to_user = array_shift($router_item['page_arguments']); + } + // Only display the local task on other users profile, not current user's. + if (!empty($to_user) && $user->uid != $to_user->uid) { + $item = menu_get_item('admin/content/message/create/private-message'); + $item['title'] = t('Create a new message for') . ' ' . $to_user->name; + $item['localized_options']['query'] = array('field_message_user_ref' => $to_user->uid); + $data['actions']['output'][] = array( + '#theme' => 'menu_local_action', + '#link' => $item, + ); + + } + + break; case 'user/%/messages': // Add a 'Create a new message' action link above message_private view. $item = menu_get_item('admin/content/message/create/private-message'); @@ -154,9 +172,9 @@ function message_private_menu_local_tasks_alter(&$data, $router_item, $root_path break; case 'message/%': - // Add a Messages tab to the private_message Message entities. $message = menu_get_object('message', 1, $router_item['href']); if (isset($message->type) && $message->type == 'private_message') { + // Add a Messages tab to the private_message Message entities. $item = menu_get_item('user/' . $user->uid . '/messages'); $item['title'] = t('Messages'); $data['tabs'][0]['output'][] = array( @@ -164,6 +182,19 @@ function message_private_menu_local_tasks_alter(&$data, $router_item, $root_path '#link' => $item, ); + // Get from user to Add a 'Create a new message for %user' action link. + $to_user = user_load($message->uid); + // Display the local task on other users profile, not current user's. + if (!empty($to_user) && $user->uid != $to_user->uid) { + $item = menu_get_item('admin/content/message/create/private-message'); + $item['title'] = t('Create a new message for') . ' ' . $to_user->name; + $item['localized_options']['query'] = array('field_message_user_ref' => $to_user->uid); + $data['actions']['output'][] = array( + '#theme' => 'menu_local_action', + '#link' => $item, + ); + + } } break; } diff --git a/message_private_og/message_private_og.install b/message_private_og/message_private_og.install index a9541df..98ab0b9 100644 --- a/message_private_og/message_private_og.install +++ b/message_private_og/message_private_og.install @@ -43,12 +43,12 @@ function message_private_og_install() { $field_bases = array(); - $field_bases['field_message_groups_ref'] = array( + $field_bases['field_message_group_ref'] = array( 'active' => 1, 'cardinality' => -1, 'deleted' => 0, 'entity_types' => array(), - 'field_name' => 'field_message_groups_ref', + 'field_name' => 'field_message_group_ref', 'foreign keys' => array( 'node' => array( 'columns' => array( @@ -90,7 +90,7 @@ function message_private_og_install() { $field_instances = array(); - $field_instances['message-private_message-field_message_groups_ref'] = array( + $field_instances['message-private_message-field_message_group_ref'] = array( 'bundle' => 'private_message', 'default_value' => NULL, 'deleted' => 0, @@ -119,7 +119,7 @@ function message_private_og_install() { ), ), 'entity_type' => 'message', - 'field_name' => 'field_message_groups_ref', + 'field_name' => 'field_message_group_ref', 'label' => $t('Groups'), 'required' => 0, 'settings' => array( @@ -173,5 +173,5 @@ function message_private_og_disable() { * Deletes the fields defined by this module. */ function message_private_og_uninstall() { - field_delete_field('field_message_groups_ref'); + field_delete_field('field_message_group_ref'); } diff --git a/message_private_og/message_private_og.module b/message_private_og/message_private_og.module index 9973cfb..cd4e06f 100755 --- a/message_private_og/message_private_og.module +++ b/message_private_og/message_private_og.module @@ -162,7 +162,7 @@ function message_private_og_access_control($operation, $message, $user_obj = NUL return TRUE; } // Check if message was sent to groups and check view access per group. - $groups = field_get_items('message', $message, 'field_message_groups_ref'); + $groups = field_get_items('message', $message, 'field_message_group_ref'); if ($groups && is_array($groups)) { foreach ($groups as $group_ref) { if (og_user_access('node', $group_ref['target_id'], @@ -215,9 +215,9 @@ function message_private_og_form_message_ui_instance_message_manage_validate($fo // If no User or Group reference is added, present an error. if (empty($form_state['values']['field_message_user_ref'][LANGUAGE_NONE][0]['target_id']) - && empty($form_state['values']['field_message_groups_ref'][LANGUAGE_NONE][0]['target_id'])) { + && empty($form_state['values']['field_message_group_ref'][LANGUAGE_NONE][0]['target_id'])) { form_error($form['field_message_user_ref'], t('A User or Groups reference is required.')); - form_error($form['field_message_groups_ref']); + form_error($form['field_message_group_ref']); } /* * TODO: Use the below global permissions to provide full access. @@ -250,7 +250,7 @@ function message_private_og_message_insert($message) { $wrapper = entity_metadata_wrapper('message', $message); $mail = array(); - $groups = $wrapper->field_message_groups_ref->value(); + $groups = $wrapper->field_message_group_ref->value(); if (!empty($groups) && is_array($groups)) { foreach ($groups as $group) { diff --git a/message_private_og/views/message_private_og.views.inc b/message_private_og/views/message_private_og.views.inc index 0fa6e31..c879da6 100644 --- a/message_private_og/views/message_private_og.views.inc +++ b/message_private_og/views/message_private_og.views.inc @@ -14,7 +14,7 @@ function message_private_og_views_default_views_alter(&$views) { $handler->display->display_options['style_plugin'] = 'table'; $handler->display->display_options['style_options']['columns'] = array( 'field_message_user_ref' => 'field_message_user_ref', - 'field_message_groups_ref' => 'field_message_user_ref', + 'field_message_group_ref' => 'field_message_user_ref', 'field_message_subject' => 'field_message_subject', 'view' => 'view', 'delete' => 'view', @@ -27,7 +27,7 @@ function message_private_og_views_default_views_alter(&$views) { 'separator' => ', ', 'empty_column' => 0, ), - 'field_message_groups_ref' => array( + 'field_message_group_ref' => array( 'align' => '', 'separator' => '', 'empty_column' => 0, @@ -63,13 +63,13 @@ function message_private_og_views_default_views_alter(&$views) { $handler->display->display_options['defaults']['row_options'] = FALSE; $handler->display->display_options['fields']['field_message_user_ref']['label'] = 'To Users / Groups'; /* Field: Message: Groups */ - $handler->display->display_options['fields']['field_message_groups_ref']['id'] = 'field_message_groups_ref'; - $handler->display->display_options['fields']['field_message_groups_ref']['table'] = 'field_data_field_message_groups_ref'; - $handler->display->display_options['fields']['field_message_groups_ref']['field'] = 'field_message_groups_ref'; - $handler->display->display_options['fields']['field_message_groups_ref']['settings'] = array( + $handler->display->display_options['fields']['field_message_group_ref']['id'] = 'field_message_group_ref'; + $handler->display->display_options['fields']['field_message_group_ref']['table'] = 'field_data_field_message_group_ref'; + $handler->display->display_options['fields']['field_message_group_ref']['field'] = 'field_message_group_ref'; + $handler->display->display_options['fields']['field_message_group_ref']['settings'] = array( 'link' => 1, ); - $handler->display->display_options['fields']['field_message_groups_ref']['delta_offset'] = '0'; + $handler->display->display_options['fields']['field_message_group_ref']['delta_offset'] = '0'; // Get handler for a new display "OG Messages". $handler =& $views['message_private']->new_display('page', 'OG Messages', 'page_3'); @@ -83,14 +83,14 @@ function message_private_og_views_default_views_alter(&$views) { $handler->display->display_options['fields']['name']['relationship'] = 'user'; $handler->display->display_options['fields']['name']['label'] = 'From User'; /* Field: Message: Groups */ - $handler->display->display_options['fields']['field_message_groups_ref']['id'] = 'field_message_groups_ref'; - $handler->display->display_options['fields']['field_message_groups_ref']['table'] = 'field_data_field_message_groups_ref'; - $handler->display->display_options['fields']['field_message_groups_ref']['field'] = 'field_message_groups_ref'; - $handler->display->display_options['fields']['field_message_groups_ref']['label'] = 'To Groups'; - $handler->display->display_options['fields']['field_message_groups_ref']['settings'] = array( + $handler->display->display_options['fields']['field_message_group_ref']['id'] = 'field_message_group_ref'; + $handler->display->display_options['fields']['field_message_group_ref']['table'] = 'field_data_field_message_group_ref'; + $handler->display->display_options['fields']['field_message_group_ref']['field'] = 'field_message_group_ref'; + $handler->display->display_options['fields']['field_message_group_ref']['label'] = 'To Groups'; + $handler->display->display_options['fields']['field_message_group_ref']['settings'] = array( 'link' => 0, ); - $handler->display->display_options['fields']['field_message_groups_ref']['delta_offset'] = '0'; + $handler->display->display_options['fields']['field_message_group_ref']['delta_offset'] = '0'; /* Field: Message: Subject */ $handler->display->display_options['fields']['field_message_subject']['id'] = 'field_message_subject'; $handler->display->display_options['fields']['field_message_subject']['table'] = 'field_data_field_message_subject'; @@ -122,15 +122,15 @@ function message_private_og_views_default_views_alter(&$views) { $handler->display->display_options['arguments']['null']['summary']['number_of_records'] = '0'; $handler->display->display_options['arguments']['null']['summary']['format'] = 'default_summary'; $handler->display->display_options['arguments']['null']['summary_options']['items_per_page'] = '25'; - /* Contextual filter: Message: Groups (field_message_groups_ref) */ - $handler->display->display_options['arguments']['field_message_groups_ref_target_id']['id'] = 'field_message_groups_ref_target_id'; - $handler->display->display_options['arguments']['field_message_groups_ref_target_id']['table'] = 'field_data_field_message_groups_ref'; - $handler->display->display_options['arguments']['field_message_groups_ref_target_id']['field'] = 'field_message_groups_ref_target_id'; - $handler->display->display_options['arguments']['field_message_groups_ref_target_id']['default_action'] = 'default'; - $handler->display->display_options['arguments']['field_message_groups_ref_target_id']['default_argument_type'] = 'og_user_groups'; - $handler->display->display_options['arguments']['field_message_groups_ref_target_id']['summary']['number_of_records'] = '0'; - $handler->display->display_options['arguments']['field_message_groups_ref_target_id']['summary']['format'] = 'default_summary'; - $handler->display->display_options['arguments']['field_message_groups_ref_target_id']['summary_options']['items_per_page'] = '25'; + /* Contextual filter: Message: Groups (field_message_group_ref) */ + $handler->display->display_options['arguments']['field_message_group_ref_target_id']['id'] = 'field_message_group_ref_target_id'; + $handler->display->display_options['arguments']['field_message_group_ref_target_id']['table'] = 'field_data_field_message_group_ref'; + $handler->display->display_options['arguments']['field_message_group_ref_target_id']['field'] = 'field_message_group_ref_target_id'; + $handler->display->display_options['arguments']['field_message_group_ref_target_id']['default_action'] = 'default'; + $handler->display->display_options['arguments']['field_message_group_ref_target_id']['default_argument_type'] = 'og_user_groups'; + $handler->display->display_options['arguments']['field_message_group_ref_target_id']['summary']['number_of_records'] = '0'; + $handler->display->display_options['arguments']['field_message_group_ref_target_id']['summary']['format'] = 'default_summary'; + $handler->display->display_options['arguments']['field_message_group_ref_target_id']['summary_options']['items_per_page'] = '25'; $handler->display->display_options['defaults']['filter_groups'] = FALSE; $handler->display->display_options['defaults']['filters'] = FALSE; /* Filter criterion: Message: Type */ @@ -140,16 +140,16 @@ function message_private_og_views_default_views_alter(&$views) { $handler->display->display_options['filters']['type_1']['value'] = array( 'private_message' => 'private_message', ); - /* Filter criterion: Message: Groups (field_message_groups_ref) */ - $handler->display->display_options['filters']['field_message_groups_ref_target_id']['id'] = 'field_message_groups_ref_target_id'; - $handler->display->display_options['filters']['field_message_groups_ref_target_id']['table'] = 'field_data_field_message_groups_ref'; - $handler->display->display_options['filters']['field_message_groups_ref_target_id']['field'] = 'field_message_groups_ref_target_id'; - $handler->display->display_options['filters']['field_message_groups_ref_target_id']['exposed'] = TRUE; - $handler->display->display_options['filters']['field_message_groups_ref_target_id']['expose']['operator_id'] = 'field_message_groups_ref_target_id_op'; - $handler->display->display_options['filters']['field_message_groups_ref_target_id']['expose']['label'] = 'Groups'; - $handler->display->display_options['filters']['field_message_groups_ref_target_id']['expose']['operator'] = 'field_message_groups_ref_target_id_op'; - $handler->display->display_options['filters']['field_message_groups_ref_target_id']['expose']['identifier'] = 'field_message_groups_ref_target_id'; - $handler->display->display_options['filters']['field_message_groups_ref_target_id']['expose']['remember_roles'] = array( + /* Filter criterion: Message: Groups (field_message_group_ref) */ + $handler->display->display_options['filters']['field_message_group_ref_target_id']['id'] = 'field_message_group_ref_target_id'; + $handler->display->display_options['filters']['field_message_group_ref_target_id']['table'] = 'field_data_field_message_group_ref'; + $handler->display->display_options['filters']['field_message_group_ref_target_id']['field'] = 'field_message_group_ref_target_id'; + $handler->display->display_options['filters']['field_message_group_ref_target_id']['exposed'] = TRUE; + $handler->display->display_options['filters']['field_message_group_ref_target_id']['expose']['operator_id'] = 'field_message_group_ref_target_id_op'; + $handler->display->display_options['filters']['field_message_group_ref_target_id']['expose']['label'] = 'Groups'; + $handler->display->display_options['filters']['field_message_group_ref_target_id']['expose']['operator'] = 'field_message_group_ref_target_id_op'; + $handler->display->display_options['filters']['field_message_group_ref_target_id']['expose']['identifier'] = 'field_message_group_ref_target_id'; + $handler->display->display_options['filters']['field_message_group_ref_target_id']['expose']['remember_roles'] = array( 2 => '2', 1 => 0, 3 => 0,