Commit bc395df3 authored by New Zeal's avatar New Zeal

create tabs and improve workflow

parent ec1baba4
...@@ -25,4 +25,7 @@ Add cache context to breadcrumbs ...@@ -25,4 +25,7 @@ Add cache context to breadcrumbs
Add message history functionality Add message history functionality
8.x-1.0-alpha9 8.x-1.0-alpha9
Fix thread delete function Fix thread delete function
\ No newline at end of file
8.x-1.0-alpha10
Make the threads control area tidier adding tabs and improving workflow
\ No newline at end of file
uuid: 0de98e51-c4df-42a7-89ba-754ec06dd8bb
langcode: en langcode: en
status: true status: true
dependencies: dependencies:
config: config:
- field.storage.message_thread.field_thread_participants - field.storage.message_thread.field_thread_participants
- message_thread.template.conversation - message_thread.template.conversation
_core:
default_config_hash: t_dV_y17DnRHyNwlueXJMi7T1cHvcCvVHwyEs-6wDjs
id: message_thread.conversation.field_thread_participants id: message_thread.conversation.field_thread_participants
field_name: field_thread_participants field_name: field_thread_participants
entity_type: message_thread entity_type: message_thread
bundle: conversation bundle: conversation
label: Participants label: Participants
description: '' description: ''
required: false required: true
translatable: false translatable: false
default_value: { } default_value: { }
default_value_callback: '' default_value_callback: ''
......
uuid: 16ab6995-bb35-4142-8ecd-cfc929c19d21
langcode: en langcode: en
status: true status: true
dependencies: dependencies:
config: config:
- field.storage.message_thread.field_thread_title - field.storage.message_thread.field_thread_title
- message_thread.template.conversation - message_thread.template.conversation
_core:
default_config_hash: xTQTQtfQ7g24lXlcZGO3u6B4FjjXVf0PM7zv9iuUqHk
id: message_thread.conversation.field_thread_title id: message_thread.conversation.field_thread_title
field_name: field_thread_title field_name: field_thread_title
entity_type: message_thread entity_type: message_thread
bundle: conversation bundle: conversation
label: Title label: Title
description: 'A title to give this conversation' description: 'A title to give this conversation'
required: false required: true
translatable: false translatable: false
default_value: { } default_value: { }
default_value_callback: '' default_value_callback: ''
......
uuid: ad109b3f-5d82-44c3-b803-8a11a077b523
langcode: en langcode: en
status: true status: true
dependencies: dependencies:
module: module:
- message_thread - message_thread
- user - user
_core:
default_config_hash: MC0s-7agSyiBQAjqJWOmRm490W1whtpovjURVdaQ4N8
id: message_thread.field_thread_participants id: message_thread.field_thread_participants
field_name: field_thread_participants field_name: field_thread_participants
entity_type: message_thread entity_type: message_thread
......
uuid: ac9b814d-5eda-424d-82d2-352d4eddb13e
langcode: en langcode: en
status: true status: true
dependencies: dependencies:
module: module:
- message_thread - message_thread
_core:
default_config_hash: L_o3YUa1iSamaRLlqZ_sHEv8nZZWH8j-DQE-ErS4GiI
id: message_thread.field_thread_title id: message_thread.field_thread_title
field_name: field_thread_title field_name: field_thread_title
entity_type: message_thread entity_type: message_thread
...@@ -17,4 +20,4 @@ cardinality: 1 ...@@ -17,4 +20,4 @@ cardinality: 1
translatable: true translatable: true
indexes: { } indexes: { }
persist_with_no_fields: false persist_with_no_fields: false
custom_storage: false custom_storage: false
\ No newline at end of file
...@@ -8,6 +8,7 @@ dependencies: ...@@ -8,6 +8,7 @@ dependencies:
module: module:
- message_private - message_private
- message_thread - message_thread
- user
_core: _core:
default_config_hash: UqAY1HdOAH7JtNrXnK5OGCxXSIJ6uZhbgRMT488UMSw default_config_hash: UqAY1HdOAH7JtNrXnK5OGCxXSIJ6uZhbgRMT488UMSw
id: conversations id: conversations
...@@ -236,20 +237,7 @@ display: ...@@ -236,20 +237,7 @@ display:
plugin_id: bundle plugin_id: bundle
sorts: { } sorts: { }
title: Messages title: Messages
header: header: { }
area:
id: area
table: views
field: area
relationship: none
group_type: group
admin_label: ''
empty: true
tokenize: false
content:
value: '<a href="/message-thread/add/conversation">Start a new conversation</a>'
format: basic_html
plugin_id: text
footer: { } footer: { }
empty: { } empty: { }
relationships: { } relationships: { }
...@@ -301,6 +289,112 @@ display: ...@@ -301,6 +289,112 @@ display:
tags: tags:
- 'config:field.storage.message_thread.field_thread_participants' - 'config:field.storage.message_thread.field_thread_participants'
- 'config:field.storage.message_thread.field_thread_title' - 'config:field.storage.message_thread.field_thread_title'
block_1:
display_plugin: block
id: block_1
display_title: Inbox
position: 2
display_options:
display_extenders: { }
display_description: ''
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- user.permissions
tags:
- 'config:field.storage.message_thread.field_thread_participants'
- 'config:field.storage.message_thread.field_thread_title'
block_2:
display_plugin: block
id: block_2
display_title: Sent
position: 3
display_options:
display_extenders: { }
display_description: ''
filters:
template:
id: template
table: message_thread_field_data
field: template
value:
conversation: conversation
entity_type: message_thread
entity_field: template
plugin_id: bundle
uid_current:
id: uid_current
table: users
field: uid_current
relationship: uid
group_type: group
admin_label: ''
operator: '='
value: '1'
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
entity_type: user
plugin_id: user_current
defaults:
filters: false
filter_groups: false
relationships: false
filter_groups:
operator: AND
groups:
1: AND
relationships:
uid:
id: uid
table: message_thread_field_data
field: uid
relationship: none
group_type: group
admin_label: User
required: true
entity_type: message_thread
entity_field: uid
plugin_id: standard
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- user
- user.permissions
tags:
- 'config:field.storage.message_thread.field_thread_participants'
- 'config:field.storage.message_thread.field_thread_title'
page_1: page_1:
display_plugin: page display_plugin: page
id: page_1 id: page_1
......
...@@ -52,26 +52,9 @@ display: ...@@ -52,26 +52,9 @@ display:
sort_asc_label: Asc sort_asc_label: Asc
sort_desc_label: Desc sort_desc_label: Desc
pager: pager:
type: full type: none
options: options:
items_per_page: 25
offset: 0 offset: 0
id: 0
total_pages: null
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous: ' previous'
next: 'next ›'
first: '« first'
last: 'last »'
quantity: 9
style: style:
type: table type: table
options: options:
...@@ -440,7 +423,7 @@ display: ...@@ -440,7 +423,7 @@ display:
group_type: group group_type: group
admin_label: '' admin_label: ''
label: '' label: ''
exclude: true exclude: false
alter: alter:
alter_text: false alter_text: false
text: '' text: ''
...@@ -485,59 +468,6 @@ display: ...@@ -485,59 +468,6 @@ display:
absolute: false absolute: false
entity_type: message entity_type: message
plugin_id: entity_link_edit plugin_id: entity_link_edit
view_message:
id: view_message
table: message
field: view_message
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: false
alter:
alter_text: true
text: "{{ view_message }}\n{{ edit_message }}"
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
text: view
output_url_as_text: false
absolute: false
entity_type: message
plugin_id: entity_link
filters: { } filters: { }
sorts: sorts:
created: created:
......
entity.message_thread.edit_form: # Message thread tabs
route_name: entity.message_thread.edit_form task.message_thread.threads:
base_route: entity.message_thread.canonical route_name: message_thread.threads
title: Edit base_route: message_thread.threads
title: Inbox
task.message_thread.threads.sent:
route_name: message_thread.threads.sent
base_route: message_thread.threads
title: Sent
task.message_thread.threads:
route_name: message_thread.threads
base_route: message_thread.threads
title: Inbox
entity.message_thread.canonical: task.message_thread.add:
route_name: message_thread.add_page
base_route: message_thread.threads
title: Add new Message
task.message_thread.canonical:
route_name: entity.message_thread.canonical route_name: entity.message_thread.canonical
base_route: entity.message_thread.canonical base_route: message_thread.threads
title: View title: View
# Tabs for message management task.message_thread.edit_form:
route_name: entity.message_thread.edit_form
base_route: message_thread.threads
title: Edit
task.message_thread.delete_form:
route_name: entity.message_thread.delete_form
base_route: message_thread.threads
title: Delete
## Provide dynamic local tasks. ## Provide dynamic local tasks.
message_thread.dynamic_tasks: message_thread.dynamic_tasks:
......
...@@ -19,6 +19,7 @@ use Drupal\Core\Access\AccessResult; ...@@ -19,6 +19,7 @@ use Drupal\Core\Access\AccessResult;
use Drupal\message_thread\MessageThreadAccessControlHandler; use Drupal\message_thread\MessageThreadAccessControlHandler;
use Drupal\message_private\MessagePrivateAccessControlHandler; use Drupal\message_private\MessagePrivateAccessControlHandler;
use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Utility\LinkGenerator;
/** /**
* Implements hook_installed. * Implements hook_installed.
...@@ -107,12 +108,32 @@ function message_thread_submit_message(array &$form, FormStateInterface $form_st ...@@ -107,12 +108,32 @@ function message_thread_submit_message(array &$form, FormStateInterface $form_st
)->execute(); )->execute();
} }
/*
* Implements hook_form_FORM_ID_alter().
*/
function message_thread_form_message_private_message_edit_form_alter(array &$form, FormStateInterface $form_state) {
// Redirect to the thread not the message
$mid = $form_state->getFormObject()->getEntity()->id();
$params = array(
'message_thread' => message_thread_relationship($mid)
);
$url = Url::fromRoute('entity.message_thread.canonical', $params);
$form_state->setRedirectUrl($url);
$link = [
'#type' => 'link',
'#url' => $url,
'#title' => t('Cancel')
];
$form['actions']['cancel'] = $link;
}
/* /*
* Implements hook_form_FORM_ID_alter(). * Implements hook_form_FORM_ID_alter().
*/ */
function message_thread_form_message_thread_conversation_edit_form_alter(array &$form, FormStateInterface $form_state) { function message_thread_form_message_thread_conversation_edit_form_alter(array &$form, FormStateInterface $form_state) {
$form['field_thread_participants']['widget']['add_more']['#value'] = new TranslatableMarkup('Add another user'); $form['field_thread_participants']['widget']['add_more']['#value'] = new TranslatableMarkup('Add another user');
$form['owner']['#access'] = \Drupal::currentUser()->hasPermission('bypass private message access control'); $form['owner']['#access'] = \Drupal::currentUser()->hasPermission('bypass private message access control');
$form['advanced']['#access'] = \Drupal::currentUser()->hasPermission('bypass private message access control');
} }
/* /*
...@@ -121,6 +142,7 @@ function message_thread_form_message_thread_conversation_edit_form_alter(array & ...@@ -121,6 +142,7 @@ function message_thread_form_message_thread_conversation_edit_form_alter(array &
function message_thread_form_message_thread_conversation_form_alter(array &$form, FormStateInterface $form_state) { function message_thread_form_message_thread_conversation_form_alter(array &$form, FormStateInterface $form_state) {
$form['field_thread_participants']['widget']['add_more']['#value'] = new TranslatableMarkup('Add another user'); $form['field_thread_participants']['widget']['add_more']['#value'] = new TranslatableMarkup('Add another user');
$form['owner']['#access'] = \Drupal::currentUser()->hasPermission('bypass private message access control'); $form['owner']['#access'] = \Drupal::currentUser()->hasPermission('bypass private message access control');
$form['advanced']['#access'] = \Drupal::currentUser()->hasPermission('bypass private message access control');
} }
/** /**
* Implements hook_preprocess_links(). * Implements hook_preprocess_links().
...@@ -291,7 +313,7 @@ function message_thread_reply_link($entity, $component) { ...@@ -291,7 +313,7 @@ function message_thread_reply_link($entity, $component) {
); );
$options = [ $options = [
'query' => [ 'query' => [
'destination' => '/message-thread/' . $entity->id() 'destination' => '/message/thread/' . $entity->id()
] ]
]; ];
$url = Url::fromRoute('message_thread.reply', $params, $options); $url = Url::fromRoute('message_thread.reply', $params, $options);
...@@ -336,8 +358,6 @@ function message_thread_message_count($entity) { ...@@ -336,8 +358,6 @@ function message_thread_message_count($entity) {
function message_thread_add_message_form_submit(&$form, FormStateInterface &$form_state) { function message_thread_add_message_form_submit(&$form, FormStateInterface &$form_state) {
$values = $form_state->getValues(); $values = $form_state->getValues();
return; return;
} }
/** /**
...@@ -405,3 +425,62 @@ function message_thread_tab_access_check() { ...@@ -405,3 +425,62 @@ function message_thread_tab_access_check() {
return AccessResult::allowedIfHasPermission($account, 'bypass private message access control'); return AccessResult::allowedIfHasPermission($account, 'bypass private message access control');
} }
/*
* Helper function to relate a message to its thread
*/
function message_thread_relationship($mid) {
$thread_id = db_select('message_thread_index', 'mdi')
->condition('mdi.mid', $mid)
->fields('mdi', ['thread_id'])
->execute()
->fetchField();
return $thread_id;
}
/*
* Helper function to get all message ids in a thread
*/
function message_thread_get_messages($thread_id) {
$result = db_select('message_thread_index', 'mdi')
->condition('mdi.thread_id', $thread_id)
->fields('mdi', ['mid'])
->execute()
->fetchAll();
$messages = [];
foreach ($result as $record) {
$messages[] = $record->mid;
}
return $messages;
}
/**
* Implements hook_ENTITY_TYPE_view_alter() for message thread entities.
*/
function message_history_message_thread_view_alter(array &$build, EntityInterface $message_thread,
EntityViewDisplayInterface
$display) {
// Update the message_history table, stating that this user viewed all messages in this thread.
if (!\Drupal::service('module_handler')->moduleExists('message_history')) {
return;
}
if (!in_array($display->getOriginalMode(), ['default', 'full'])) {
return;
}
$build['#cache']['contexts'][] = 'user.roles:authenticated';
if (!\Drupal::currentUser()->isAuthenticated()) {
return;
}
// Find all messages in this thread and mark them read
$messages = message_thread_get_messages($message_thread->id());
foreach ($messages as $mid) {
$build['#attached']['drupalSettings']['message_history']['itemsToMarkAsRead'][$mid] = TRUE;
}
$build['#attached']['library'][] = 'message_history/mark-as-read';
}
\ No newline at end of file
...@@ -17,7 +17,7 @@ message_thread.overview_templates: ...@@ -17,7 +17,7 @@ message_thread.overview_templates:
#message_thread.thread_add: #message_thread.thread_add:
# path: '/message-thread/add' # path: '/message/thread/add'
# defaults: # defaults:
# _entity_form: 'message_thread.add' # _entity_form: 'message_thread.add'
# _title: 'Add message thread' # _title: 'Add message thread'
...@@ -49,7 +49,7 @@ entity.message_thread_template.delete_form: ...@@ -49,7 +49,7 @@ entity.message_thread_template.delete_form:
_permission: 'administer message templates' _permission: 'administer message templates'
message_thread.add_page: message_thread.add_page:
path: '/message-thread/add' path: '/message/thread/add'
defaults: defaults:
_title: 'Add Message Thread' _title: 'Add Message Thread'
_controller: '\Drupal\message_thread\Controller\MessageThreadController::addPage' _controller: '\Drupal\message_thread\Controller\MessageThreadController::addPage'
...@@ -58,7 +58,7 @@ message_thread.add_page: ...@@ -58,7 +58,7 @@ message_thread.add_page:
_entity_create_access: 'message_thread' _entity_create_access: 'message_thread'
message_thread.add: message_thread.add:
path: '/message-thread/add/{message_thread_template}' path: '/message/thread/add/{message_thread_template}'
defaults: defaults:
# Calls the form.add controller, defined in the message entity alter hook. # Calls the form.add controller, defined in the message entity alter hook.
_controller: '\Drupal\message_thread\Controller\MessageThreadController::add' _controller: '\Drupal\message_thread\Controller\MessageThreadController::add'
...@@ -71,7 +71,7 @@ message_thread.add: ...@@ -71,7 +71,7 @@ message_thread.add:
with_config_overrides: FALSE with_config_overrides: FALSE
entity.message_thread.edit_form: entity.message_thread.edit_form:
path: '/message-thread/{message_thread}/edit' path: '/message/thread/{message_thread}/edit'
defaults: defaults:
# Calls the form.edit controller, defined in the message entity alter hook. # Calls the form.edit controller, defined in the message entity alter hook.
_entity_form: message_thread.edit _entity_form: message_thread.edit
...@@ -80,7 +80,7 @@ entity.message_thread.edit_form: ...@@ -80,7 +80,7 @@ entity.message_thread.edit_form:
_entity_access: 'message_thread.edit' _entity_access: 'message_thread.edit'
entity.message_thread.delete_form: entity.message_thread.delete_form:
path: '/message-thread/{message_thread}/delete' path: '/message/thread/{message_thread}/delete'
defaults: defaults:
# Calls the form.delete controller, defined in the message entity alter hook. # Calls the form.delete controller, defined in the message entity alter hook.
_entity_form: message_thread.delete _entity_form: message_thread.delete
...@@ -89,7 +89,7 @@ entity.message_thread.delete_form: ...@@ -89,7 +89,7 @@ entity.message_thread.delete_form:
_entity_access: 'message_thread.delete' _entity_access: 'message_thread.delete'
message_thread.threads: message_thread.threads:
path: '/user/{user}/threads' path: '/message/threads'
defaults: defaults:
_controller: '\Drupal\message_thread\Controller\MessageThreadController::inbox' _controller: '\Drupal\message_thread\Controller\MessageThreadController::inbox'
_title: 'Message Threads' _title: 'Message Threads'
...@@ -98,7 +98,7 @@ message_thread.threads: ...@@ -98,7 +98,7 @@ message_thread.threads:
_permission: 'overview message threads' _permission: 'overview message threads'
message_thread.threads.inbox: message_thread.threads.inbox:
path: '/user/{user}/threads/inbox' path: '/message/threads/inbox'
defaults: defaults:
_controller: '\Drupal\message_thread\Controller\MessageThreadController::inbox' _controller: '\Drupal\message_thread\Controller\MessageThreadController::inbox'
_title: 'Inbox' _title: 'Inbox'
...@@ -107,16 +107,16 @@ message_thread.threads.inbox: ...@@ -107,16 +107,16 @@ message_thread.threads.inbox:
_permission: 'overview message threads' _permission: 'overview message threads'
message_thread.threads.sent: message_thread.threads.sent:
path: '/user/{user}/threads/sent' path: '/message/threads/sent'
defaults: defaults:
_controller: '\Drupal\message_thread\Controller\MessageThreadController::sent' _controller: '\Drupal\message_thread\Controller\MessageThreadController::sent'
_title: 'Sent' _title: 'Sent'
description: 'Message Thread Sent' description: 'Message Thread Sent'
requirements: requirements:
_permission: 'overview messages' _permission: 'overview message threads'
#entity.message_thread.canonical: #entity.message_thread.canonical:
# path: '/message-thread/{message_thread}' # path: '/message/thread/{message_thread}'
# defaults: # defaults:
# # Calls the view controller, defined the message entity alter hook. # # Calls the view controller, defined the message entity alter hook.
# _entity_view: 'message_thread' # _entity_view: 'message_thread'
...@@ -137,13 +137,5 @@ message_thread.reply: ...@@ -137,13 +137,5 @@ message_thread.reply:
message_template: message_template:
with_config_overrides: FALSE with_config_overrides: FALSE
# The default View that comes with this module
#message_thread.conversations:
# path: '/user/{user}/conversations'